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? Commented Jan 28, 2015 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. Commented Jan 28, 2015 at 14:03

2 Answers 2

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.