Title: return sidebar as a variable
Last modified: August 19, 2016

---

# return sidebar as a variable

 *  Resolved [psychomachine](https://wordpress.org/support/users/psychomachine/)
 * (@psychomachine)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/return-sidebar-as-a-variable/)
 * 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

Viewing 1 replies (of 1 total)

 *  Thread Starter [psychomachine](https://wordpress.org/support/users/psychomachine/)
 * (@psychomachine)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/return-sidebar-as-a-variable/#post-688513)
 * actually, good old buffering does the trick
 *     ```
       ob_start(); // Start output buffering.
       	get_sidebar();
       	$sidebar = ob_get_clean();
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘return sidebar as a variable’ is closed to new replies.

## Tags

 * [content](https://wordpress.org/support/topic-tag/content/)
 * [eval](https://wordpress.org/support/topic-tag/eval/)
 * [output](https://wordpress.org/support/topic-tag/output/)
 * [print](https://wordpress.org/support/topic-tag/print/)
 * [return](https://wordpress.org/support/topic-tag/return/)
 * [sidebar](https://wordpress.org/support/topic-tag/sidebar/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [psychomachine](https://wordpress.org/support/users/psychomachine/)
 * Last activity: [18 years, 4 months ago](https://wordpress.org/support/topic/return-sidebar-as-a-variable/#post-688513)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
