[Resolved] Stop the Featured Image from Being Pinnable

Home Forums Support [Resolved] Stop the Featured Image from Being Pinnable

Home Forums Support Stop the Featured Image from Being Pinnable

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1036449
    hoya

    I want to prevent my featured images from being pinnable. Should I add the following to the functions.php file?

    /**
    * Disable pinning of all featured images.
    */
    add_filter( ‘post_thumbnail_html’, function( $html ){
    // Something already has ‘data-pin-nopin’, so we don’t need to modify.
    if ( false !== stripos( $html, ‘data-pin-nopin’ ) ) {
    return $html;
    }
    // Add ‘data-pin-nopin’ to the HTML tag.
    $html = str_replace( ‘<img ‘, ‘<img data-pin-nopin=”true” ‘, $html );
    return $html;
    });

    #1036509
    David
    Staff
    Customer Support

    Hi there,

    this article explains adding PHP:
    https://docs.generatepress.com/article/adding-php/

    You should never edit the Theme files, only a Child Theme file.

    #1036559
    hoya

    Thank you! Yes, I would add it to my child theme.

    #1036568
    David
    Staff
    Customer Support

    You’re welcome

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.