remove class from the_post_thumbnail (4 posts)

  1. zompus
    Posted 5 years ago #


    Why does this not work? :/

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Why are you even trying to remove the classes from the post thumbnail?

  3. zompus
    Posted 5 years ago #

    Very bad case of OCD.

    I do not use them and like to keep my code as tidy as a nuns buttocks.

    Any hint?

  4. ambrosite
    Posted 5 years ago #

    "Very bad case of OCD." Well at least you are honest. :)

    It doesn't work because 'the_post_thumbnail' is not a valid filter. You need to use 'post_thumbnail_html' if you want to filter the output, like this:

    //remove class from the_post_thumbnail
    function the_post_thumbnail_remove_class($output) {
        $output = preg_replace('<code>class=&quot;(.*?)&quot;</code>', '', $output);
        return $output;
    add_filter('post_thumbnail_html', 'the_post_thumbnail_remove_class');

    I still don't understand why you think adding a 5-line function (and a function that uses a regex, no less) in order to remove a class name makes your code any tidier. But, to each his own! ;)

Topic Closed

This topic has been closed to new replies.

About this Topic