Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hide WordPress' Categories widget on certain pages
Plugin Name: Hide Categories Listing
Plugin URI:
Description: Hide the Categories widget on certain pages.
Author: Benedict Eastaugh
Version: 1.0
Author URI:
function maybe_hide_categories_widgets($sidebars) {
if (!(is_page() || is_single())) return $sidebars;
// Add page IDs to this list, e.g.
// $hide_categories_on = array(1, 4, 9);
$hide_categories_on = array();
if (in_array(get_the_ID(), $hide_categories_on)
|| get_post_meta(get_the_ID(), 'hide_categories', true))
foreach($sidebars as $id => $sidebar)
foreach($sidebar as $i => $widget)
if (strpos($widget, "categories-") === 0)
return $sidebars;
add_filter('sidebars_widgets', 'maybe_hide_categories_widgets');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment