0

I have dozens of sub-sites with varying sidebars (some custom, some use primary, some blank).

For those logged into WordPress, is there a hook to disable the following message from blank sidebars?

This is the Primary Sidebar Widget Area. You can add content to this area by visiting your Widgets Panel and adding new widgets to this area.

It does not appear when logged out, but I'd prefer it not be there for editors either as it can be confusing. I know that I can add empty widgets there to get rid of it, but there has to be a better way.

We're using WordPress 4.9.4, Genesis 2.5.3 + custom child theme.

1 Answer 1

2

This code handles the sidebar:

add_action( 'genesis_sidebar', 'genesis_do_sidebar' );
/**
 * Echo primary sidebar default content.
 *
 * Only shows if sidebar is empty, and current user has the ability to edit theme options (manage widgets).
 *
 * @since 1.2.0
 */
function genesis_do_sidebar() {

    if ( ! dynamic_sidebar( 'sidebar' ) && current_user_can( 'edit_theme_options' )  ) {
        genesis_default_widget_area_content( __( 'Primary Sidebar Widget Area', 'genesis' ) );
    }

}

You can unhook genesis_do_sidebar from genesis_sidebar, then wire up your own sidebar function to prevent the default content from being output:

remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'wpse_genesis_do_sidebar' );
/**
 * Outputs widgets for sidebar without default content.
 */
function wpse_genesis_do_sidebar() {
    dynamic_sidebar( 'sidebar' );
}
1
  • Thank you, Dave. This appears to work, but it also removes other custom sidebars.
    – danielh
    Commented Mar 18, 2018 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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