Support » Fixing WordPress » return sidebar as a variable

  • Resolved psychomachine



    get_sidebar() works very well when you need to output the sidebar on a page. i’m wondering if there is a way to call the sidebar.php and return the evaluated content as a variable so that it can be used further in the code.

    something along the lines:

    $sidebar = return_sidebar();
    print do_something_with($sidebar);

    many thanks in advance,

Viewing 1 replies (of 1 total)
  • actually, good old buffering does the trick

    ob_start(); // Start output buffering.
    	$sidebar = ob_get_clean();
Viewing 1 replies (of 1 total)
  • The topic ‘return sidebar as a variable’ is closed to new replies.