如何在 WordPress Single Post 中隐藏特色图像

1 wordpress wordpress-theming

我想在帖子页面中隐藏特色图像,但不在主页上隐藏。
我查看了有关同一问题的其他帖子,但它们对我不起作用,所以我将感谢您的帮助。

这是我的 single.php

<div id="primary" class="full-width-page">
    <main id="main" class="site-main" role="main">

    <?php while ( have_posts() ) : the_post(); ?>

        <?php get_template_part( 'content', 'single' ); ?>

        <?php tesseract_post_nav(); ?>

        <?php
            // If comments are open or we have at least one comment, load up the comment template
            if ( comments_open() || get_comments_number() ) :
                comments_template();
            endif;
        ?>

    <?php endwhile; // end of the loop. ?>

    </main><!-- #main -->
</div><!-- #primary -->
Run Code Online (Sandbox Code Playgroud)

jus*_*tyy 5

将其添加到您的functions.php(更喜欢子主题)中,就是这样。它适用于任何主题,并且您无需接触丑陋的 HTML 模板。

function wordpress_hide_feature_image( $html, $post_id, $post_image_id ) {
  return is_single() ? '' : $html;
}
// add the filter
add_filter( 'post_thumbnail_html', 'wordpress_hide_feature_image', 10, 3);
Run Code Online (Sandbox Code Playgroud)

参考资料: https ://helloacm.com/how-to-hide-feature-image-of-posts-in-wordpress/