3

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?

  • 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
12

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.

  • worked for me! thanks! had to save the entire footer html output in a transient. thanks! – Amit Aug 31 '11 at 21:14
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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