Articles of post class

Add Post Tags to Body Class

Want to add post tag name to body class – I am successful in using the code below to add category to body class – //adds new body class for post category add_filter(‘body_class’, ‘add_category_class_single’); function add_category_class_single($classes){ global $post; $category = get_the_category($post->ID); $slug = $category[0]->slug; $classes[] = ‘post-category-‘ . $slug; return $classes; } however when i […]

Theme Check: Could not find post_class

I’ve inherited a theme from a another developer that I’ve re-styled for a client. We’re just about finished, but I thought I’d run it through the Theme-Check plug-in to see if there’s any errors or problems. Unfortunately there’s a ton. I’ve gotten rid of most of them, but I have one Required left: REQUIRED: Could […]

WordPress: How to use post_class() in an echo

I am working on a foreach loop in WordPress and want to add ‘post_class()’ to a div within it. Currently the code looks like this: if ( is_array( $posts ) && !empty( $posts ) ) { echo ‘<ul class=”tribe-related-events tribe-clearfix hfeed vcalendar”>’; foreach ( $posts as $post ) { echo ‘<li>’; echo ‘<div class=”overlay”>’; echo […]

Duplicate attribute class causing site validation error

The following bit of code results in a duplicate attribute site validation error. This template script: <div class=”clearfix” <?php post_class() ?>> produces this source output: <div class=”clearfix” class=”post-263 post type-post status-publish format-st… WordPress adds its own post-related classes to format the blog entry. Is there any way I can add my “clearfix” class to the […]

Adding body class when post contains a specific shortcode

Simple shortcode function : function my_shortcode_function($atts,$content=null){ // Do something return $content; } add_shortcode(‘my_shortcode’,’my_shortcode_function’); I wonder how to add more extra body class when user use this shortcode in contents. I can’t do something like : function my_shortcode_function($atts,$content=null){ // Do something add_filter(‘body_class’,’my_body_class’); return $content; } function my_body_class($classes) { $classes[] = ‘foo’; return $classes; } add_shortcode(‘my_shortcode’,’my_shortcode_function’); Any […]

current-menu-item class for custom post type parent

Im having a problem with my menu and custom post type. I have a custom post type of “services”. I have created new page for it called Services. On that page Im displaying a list of all the post from that custom post type. The current-menu-item class is working as itended. But the problem is […]

Remove and add class with body_class() function

I want to remove the default body class on the theme and add a new class. I use this code to do this: //REMOVE / ADD HOME CLASS FROM BODY add_filter(‘body_class’, function (array $classes) { if (in_array(‘home’, $classes)) { unset( $classes[array_search(‘home’, $classes)] ); } return $classes; }); add_filter(‘body_class’, function (array $classes) { if (in_array(‘blog’, $classes)) […]

Indirect modification of overloaded property WP_Post::$classes has no effect

I’m working on a child theme and while everything works the Walker_Nav_Menu and Walker classes are causing all the fuss. My parent theme overrides Walker_Nav_Menu as below: if ( ! class_exists( ‘Zen_Menu_Walker’ ) ) { class Zen_Menu_Walker extends Walker_Nav_Menu { public function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { $element->has_children = […]

WordPress Loop – Style rows of posts differently

I am trying to adapt the WordPress loop to style posts differently in rows that get infinitely smaller until all posts are displayed The concept here is to display posts in rows first row 1 post second row 2 posts third row 3 posts fourth row 4 posts fifth row 5 posts sixth row 6 […]

Add class to the items in wp_list_pages

I just want to add a class for the active page in the wp_list_pages().Is it possible? If so can I provide a particular class for a active page. Here is my code for listing the parent page and its sub page. <?php $output = wp_list_pages(‘echo=0&depth=1&title_li= &sort_column=menu_order’ ); if (is_page( )) { $page = $post->ID; if […]