Support » Plugins » Add page category as css class. (Different from post category page.)

  • Resolved geophray

    (@geophray)


    Hello all,

    I’ve installed the Post Tags and Categories for Pages Plugin and am able to assign pages to a category. I’m trying to target a page category for CSS purposes… I can accomplish the CSS edits I need using the page-id-xxx CSS class, but this is pretty cumbersome as there are going to be 80-100 pages in each category. Would be much better if I could get a category CSS class to be available in the page body class.

    I’m trying to work my way through this, but am no expert when it comes to functions.php and CSS and could use any help I can get. 🙂

Viewing 1 replies (of 1 total)
  • Thread Starter geophray

    (@geophray)

    I figured it out!

    I found this post on post_class and was able to tweak the example there to use the pages instead of the posts. Here is what I ended up with and it worked like a charm.

    // add page category nicenames in body class
    	function category_id_class($classes) {
    	    global $page;
    	    foreach((get_the_category($page->ID)) as $category)
    	        $classes[] = $category->category_nicename;
    	        return $classes;
    	}
    	add_filter('body_class', 'category_id_class');
Viewing 1 replies (of 1 total)
  • The topic ‘Add page category as css class. (Different from post category page.)’ is closed to new replies.