• Resolved marvc

    (@marvc)


    Be nice to have an option to exclude pages. I came across this and wonder if if can be used to exclude all pages:

    function dfi_skip_page ( $dfi_id, $post_id ) {
    if ( $post_id == 23 ) {
    return 0; // invalid id
    }
    return $dfi_id; // the original featured image id
    }
    add_filter( ‘dfi_thumbnail_id’, ‘dfi_skip_page’, 10 , 2 );

    Not what to change to exclude the feated image on all pages or where to place this.

    Any responses appreciated.

    https://www.ads-software.com/plugins/default-featured-image/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jan-Willem

    (@janwoostendorp)

    You are close.

    To exclude all pages combine it with the example of the different posttype. Like this:

    function dfi_posttype_page ( $dfi_id, $post_id ) {
      $post = get_post($post_id);
      if ( 'post' === $post->post_type ) {
        return 0; //invalid ID
      }
      return $dfi_id; // the original featured image id
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_posttype_page', 10, 2 );

    You can place it in your theme’s functions.php or create a single file plugin.

    Let me know if this helps.

    Thread Starter marvc

    (@marvc)

    Apologies but in looking at this example I still see 10, 2 which I assume represent page numbers. Should these be removed and replaced with something else? I’ll first try adding it to my theme’s function.php file as I’m 0-5 in my attempts at creating plugins.

    tia

    Plugin Author Jan-Willem

    (@janwoostendorp)

    No the 10, 2 are part of WordPress. You don’t need to change anything. This will exclude all pages from showing a DFI

    Hi

    I was looking for solution of a similar problem and this worked for me. I needed to exclude all default WordPress pages so I added this function in my child theme’s function.php:

    function dfi_posttype_page ( $dfi_id, $post_id ) {
      $post = get_post($post_id);
      if ( 'page' === $post->post_type ) {
        return 0; //invalid ID
      }
      return $dfi_id; // the original featured image id
    }
    add_filter( 'dfi_thumbnail_id', 'dfi_posttype_page', 10, 2 );

    Just changed ‘post’ to ‘page’ and got it working. I also tried with custom post types e.g., ‘custom_post_type_name’ in place of ‘post’ and that worked too.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude featured image on all pages’ is closed to new replies.