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 … Read more

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 = … Read more

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 … Read more

Alternate post_class on each post

I need to have an alternating (even, odd…) class on posts to provide alternate highlights on a column. The best thing would be to attach this to the post_class() so that it’s on every instance of post_class(). Below is the code I have at this point to achieve this effect. <?php // setting other variables … Read more

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)) … Read more