Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@beastaugh
Created April 21, 2009 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beastaugh/99131 to your computer and use it in GitHub Desktop.
Save beastaugh/99131 to your computer and use it in GitHub Desktop.
Hide WordPress' Categories widget on certain pages
<?php
/*
Plugin Name: Hide Categories Listing
Plugin URI: http://tarskitheme.com/
Description: Hide the Categories widget on certain pages.
Author: Benedict Eastaugh
Version: 1.0
Author URI: http://extralogical.net/
*/
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)
unset($sidebars[$id][$i]);
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