Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to get a sidebar and save it in a Variable,
This is impossible with the get_sidebar function since it simply prints out
the sidebar, is there another function that I can use?

share|improve this question
    
What do you want to do with this variable? –  Chip Bennett Jul 14 '11 at 13:12
    
I want to add widgets from a "page" content, so I'm trying to replace tags like %SIDEBAR_3% to the actual sidebar, so I'm using str_replace but I need a function that returns something –  Asaf Jul 14 '11 at 13:18

2 Answers 2

You probably need to use output buffering, if I understand your question correctly.

Try something like this:

ob_start();
dynamic_sidebar('sidebar-id');
$sidebar = ob_get_contents();
ob_end_clean();

That will put the output of the sidebar into the variable $sidebar, which you can then process and return from your filter on the page content.

share|improve this answer
    
worked for me! thanks! had to save the entire footer html output in a transient. thanks! –  Amit Aug 31 '11 at 21:14

The get_sidebar() function is an include function, used to include sidebar.php.

The function I think you're after is dynamic_sidebar() (Codex ref), assuming you know the ID of the dynamic sidebar you want to use.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.