1

I want to remove a widget from page with id '28'. How can I do it?

I have found function for it, but it is private function, so I can't use it.

"wp set sidebars widgets

This function's access is marked as private."

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

2
  • There are plugins for that. Jetpack has widgets visibility feature, and there are resources explaining the issue. Why not research a bit before asking? Jan 28 '15 at 13:58
  • I want to write a plugin for page with id 28. Plugin has 100 lines of code, I hope to do it with 5-6.
    – Layka
    Jan 28 '15 at 14:03
2
function my_theme_sidebars_widgets( $sidebars_widgets ) {

if(is_page(28))
    $sidebars_widgets['sidebar-10'][2] = null;

return $sidebars_widgets;
}
add_filter( 'sidebars_widgets', 'my_theme_sidebars_widgets' );

ok, I have found a filter for it. I hope this 'null' is fine.

0

You can try this one below.

add_filter( 'widget_display_callback', 'hide_widget', 50, 3 );

function hide_widget( $instance, $widget, $args ){
    if ( is_page( 28 ) ) {
        return false;
    }
    return $instance;
}

I hope this will be very helpful.

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.