0

So for a post i know how to remove a class by using

function remove_class( $classes ) {
            $classes = array_diff($classes, array('hentry'));   
        return $classes;
}

add_filter('post_class', 'remove_class');

But i need to remove a particular class from a child div of the post div, i.e. a div with class="post_image mb30 blur icon" and i like to remove blur.

It turns out the WP theme in use, adds the class by:

    function content_thumbnail_masonry($args = array()) {
 global $post; 
$args['width'] = '768'; 
$args['height'] = ''; 
$args['crop'] = false; 
$args['class'] = 'post_image mb15'; 
if (get_post_format() == 'quote') { 
$args['show'] = false; 
} elseif (get_post_format() == 'link') {
 $args['show'] = false; 
} 
return $args; }

I also tried this:

function remove_css_please( $content ) {
    global $post; 
    $postid = $post->ID;
    if( $postid==5709) {
    echo 'yes for this one';
    $content = str_replace('<div class="post_image mb30 blur icon">','<div class="post_image mb30">', $content);
    } 
    return $content;
}
add_filter('the_content', 'remove_css_please');

But the preg_replace doesn't work, the echo did show up.

i like to remove the a href tag as well

  • How is post_image added in the first place? It looks like you may have two separate questions in one. – s_ha_dum Jan 21 '14 at 15:13
  • @s_ha_dum that's a good one. I was given a theme to use, but i guess the post_image is added because of the post format is set to image. And post format is a general WP 3.8 feature. – alex Jan 21 '14 at 15:47
  • I did a quick grep for that class and didn't find it. Perhaps it is dynamically generated, but it may also be part of the theme. I am not sure, and without knowing I don't think I can help. – s_ha_dum Jan 21 '14 at 16:16
  • @s_ha_dum you are correct post_image is not a native WP class. I think function content_thumbnail_masonry($args = array()) { global $post; $args['width'] = '768'; $args['height'] = ''; $args['crop'] = false; $args['class'] = 'post_image mb15'; if (get_post_format() == 'quote') { $args['show'] = false; } elseif (get_post_format() == 'link') { $args['show'] = false; } return $args; } As i don't like to alter the theme files so i am trying to create a function in functions.php which removes the class by add_filter('the_content', 'remove_class_please'); – alex Jan 21 '14 at 19:24
  • 1
    Edit that code into the question as well as the code where that function is used. Is it hooked in somewhere? – s_ha_dum Jan 21 '14 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.