php help – widgets and sidebars
-
So…
Why can’t I get the same widget to appear on 2 sidebars?
Let’s say there’s a widget in my functions.php file that looks like this:
function skyscraper_widget() { echo ' <div id="sky-ad" class="widget">' SOME ADD CODE GOES HERE '</div>'; } wp_register_sidebar_widget('skyscraper_widget', __('Sidebar Ads'), 'skyscraper_widget');It seems to appear under “Available WIdgets” in the widget screen and I can drag it to a sidebar and then it works. Great. But now it’s not available for a second sidebar! Why is that?
I figured out by trial and error that I could create widgets by copying some of those functions and then changing the names. So If I do this:
function skyscraper_widget2() { echo ' <div id="sky-ad" class="widget">' SOME ADD CODE GOES HERE '</div>'; } wp_register_sidebar_widget('skyscraper_widget2', __('Duplicate Sidebar Ads'), 'skyscraper_widget2');Now I get a duplicate, it’s available, and I can drag it to my second sidebar.
I assume what I’m doing here is an ugly hack right? What’s the correct way to do this?
The topic ‘php help – widgets and sidebars’ is closed to new replies.