WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] return sidebar as a variable (2 posts)

  1. psychomachine
    Member
    Posted 6 years ago #

    Hi,

    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,
    Tench

  2. psychomachine
    Member
    Posted 6 years ago #

    actually, good old buffering does the trick

    ob_start(); // Start output buffering.
    	get_sidebar();
    	$sidebar = ob_get_clean();

Topic Closed

This topic has been closed to new replies.

About this Topic