Hooking in to replace the Sidebar/Widget areas

The Goal: To replace the sidebar on all sites across my network with content loaded from a plugin, across all themes.

I need a way of over-riding the sidebar/main widget area on all sites across my network.

Read More

I have written a plugin which generates the sidebar with a function call, but how can I get this content to completely replace the sidebar? At present I can only call a hook as get_sidebar() happens, not replace that action.

add_action('get_sidebar', 'my_get_sidebar', 11);

Additionally, this makes my sidebar appear on all sidebars on the page, I only want it to overwrite the main one (sidebar-one?) and have the others left blank.

Related posts

Leave a Reply

2 comments

  1. You should look into having your sidebars utilize the remove action function.

    Then you can remove a sidebar and replace it in a function any number of ways.

    For instance (this examples using a conditional based on a page called some-page.

    function change_sidebar_yay() {
        if ( is_single('some-page') ) {
            remove_action( 'old_sidebar', 'your_function' ); //this is sidebar you want removed
            add_action('get_sidebar', 'my_get_sidebar', 11);
        }
    }
    

    http://codex.wordpress.org/Function_Reference/remove_action

    The old_sidebar and your_function is the name and the function name of the sidebar you want removed, you will have to look in your theme to find the actual values the theme author used ( usually in functions.php but not always).

    Also if the theme is hardcoded or does not create sidebars using hooks/actions this will not work.