Customize your theme in the Theme Customizer panel. See changes live without page reloading.   

排除页面特色图像

当前位置:
估计的阅读时间: < 1分钟

安装Default featured image插件后,所有文章类型以及页面都会被设置特色图像,此时可以通过在主题的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 );

排除特定页面,页面id:23,

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 );

特色图像在自定义文章类型禁用

function dfi_posttype_book ( $dfi_id, $post_id ) {
  $post = get_post($post_id);
  if ( 'kb' === $post->post_type ) {
    return null; // no image
  }
  return $dfi_id; // the original featured image id
}
add_filter( 'dfi_thumbnail_id', 'dfi_posttype_book', 10, 2 );

同理, ‘post’ 改为 ‘page’ 或者‘custom_post_type_name’ 同样有效.
ref:https://wordpress.org/support/topic/exclude-featured-image-on-all-pages/

这篇文章有帮助吗?
浏览: 4
Call to action title here