WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [closed] Remove Post Thumbnail classes (13 posts)

  1. christopherburton
    Member
    Posted 1 year ago #

    How could I remove the post thumbnail classes within functions.php?

    I saw this post however, it gave an error.

  2. wpismypuppet
    Member
    Posted 1 year ago #

    What's the error?

  3. christopherburton
    Member
    Posted 1 year ago #

    Warning: preg_replace() [function.preg-replace]: Unknown modifier 'c' in C:\Users\Chris\Desktop\wamp\www\wordpress\wp-content\themes\murtaugh-HTML5-Reset-Wordpress-Theme-8aa6329\functions.php on line 164

    Line 164: $output = preg_replace('<code>class=&quot;(.*?)&quot;</code>', '', $output);

  4. wpismypuppet
    Member
    Posted 1 year ago #

    It's the correct code, but an incorrect preg_replace. Use this... I tested and it works:

    //remove class from the_post_thumbnail
    function the_post_thumbnail_remove_class($output) {
    	$output = preg_replace('/class=".*?"/', '', $output);
    	return $output;
    }
    add_filter('post_thumbnail_html', 'the_post_thumbnail_remove_class');
  5. christopherburton
    Member
    Posted 1 year ago #

    Really appreciate that.

  6. wpismypuppet
    Member
    Posted 1 year ago #

    You are welcome...

  7. christopherburton
    Member
    Posted 1 year ago #

    For some reason it leaves off the trailing '/>' of the img tag.

    Edit: My fault.

  8. wpismypuppet
    Member
    Posted 1 year ago #

    Mine is still there... make sure you check your source code, and not just through Firebug or something... my Firebug leaves it off, but my source code shows it.

  9. christopherburton
    Member
    Posted 1 year ago #

    Yeah, it's all good. I didn't see it at first but it's there.

  10. aares
    Member
    Posted 1 year ago #

    Hello, I have the same issue except that I seem to know less about codes than both of you. I'm working with Gridportfolio theme. Could you tell me where to put the code posted above and other details i should know for the 'post-thumbnails' to be disabled?
    Thanks!

  11. christopherburton
    Member
    Posted 1 year ago #

    The code above goes into the functions.php file.

  12. rabeloalexandre
    Member
    Posted 10 months ago #

    Olá, tudo bem?
    Desculpa o encomodo, mas é que estou a procura de alguém pra me quebrar um galho.
    Seguinte, tenho esse blog http://www.valmirlima.com.br que estou programando, porém ele é meio diferente dos outros, porque mesmo se eu não inserir imagem no post, aparece esse thumbnail na página principal. Como a maioria dos posts no blog não tem imagem, fica estranho né. Daí quero saber se voces podem me dar essa força, porque já procurei nos códigos e nada.
    Eu quero que apareça imagem na home apenas quando eu colocar imagem destacada, quando eu não colocar, é pra aparecer só o título e uma prévia do texto mesmo, como é na maioria dos blogs.
    Serei muito grato!

  13. alchymyth
    The Sweeper & Moderator
    Posted 10 months ago #

    @rabeloalexandre

    please post in English.

    and start a new topic.

Topic Closed

This topic has been closed to new replies.

About this Topic