hi guys is there any way to get the dynamic sidebar instead of directly echoing it.
i want something like get_dynamic_sidebar(‘sidebar’)
hi guys is there any way to get the dynamic sidebar instead of directly echoing it.
i want something like get_dynamic_sidebar(‘sidebar’)
What do you want to do with it?!
if(!function_exists('get_dynamic_sidebar'){ function get_dynamic_sidebar($index = 1) { $sidebar_contents = ""; ob_start(); dynamic_sidebar($index); $sidebar_contents = ob_get_clean(); return $sidebar_contents; } }
There are a lot of way to do it. Just depends on what you are trying to accomplish.
ZoomIt saidif(!function_exists('get_dynamic_sidebar'){ function get_dynamic_sidebar($index = 1) { $sidebar_contents = ""; ob_start(); dynamic_sidebar($index); $sidebar_contents = ob_get_clean(); return $sidebar_contents; } }
thanks a lot man it works
May somebody finally tell me what this does?
when we use dynamic_sidebar(‘sidebar’) function it simply display the sidebar.
however i wanted to rerturn the content of sidebar instead of displaying it so zoomit has given the perfect solution for that.
Hm I’m not sure if I understand the difference but thanks!
the difference between the two is same as
echo and return in PHP.
hope this makes sense
Ah! Thanks!
atinder saidthe difference between the two is same as
echo and return in PHP.
hope this makes sense
I have to disagree. If you use echo instead of return in the shortcode api, the content returned by the shortcode will be placed at the begining on the page/post, regardless of where you place it in your text.
duotive saidatinder saidthe difference between the two is same as
echo and return in PHP.
hope this makes sense
I have to disagree. If you use echo instead of return in the shortcode api, the content returned by the shortcode will be placed at the begining on the page/post, regardless of where you place it in your text.
agree with you. thats why i needed this function
in shortcode if i use dynamic_sidebar(‘sidebar’) it echos at the top of page.can’t return contents.
but if when i used the function given above i can return the contents in shortcode