不能在不删除内容的情况下删除WordPress页面标题


Not able to remove WordPress page title without removing the content aswell

我正在制作一个WordPress主题与框架从下划线。

我不希望在页面上显示页面标题。所以我想我可以用一些简单的CSS来实现:

.entry-title {display:none;}

但是这样做也会删除页面上的所有内容,基本上只是显示一个空页面。

然后我想我可以删除这个标题在我的主题:

<header class="entry-header">
    <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->

但是通过删除上面的内容也删除了所有的内容。

就像为了显示内容必须显示标题一样。我以前从来没有遇到过这个问题,我用underscore .me开发了一些主题。但这就像新版本必须显示页面标题才能显示内容。

有谁知道该怎么办吗?

我在本地主机上运行,所以我不能显示我的问题,但我正在使用来自下划线的最新主题。

即使我安装了"禁用页面标题"插件,插件也会在禁用标题时删除内容。

我真的希望以前有人遇到过这个问题!:)

额外信息:

page.php是这样的:

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php while ( have_posts() ) : the_post(); ?>
            <?php get_template_part( 'template-parts/content', 'page' ); ?>
            <?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 -->

这是它调用的模板:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
    <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->
<div class="entry-content">
    <?php the_content(); ?>
    <?php
        wp_link_pages( array(
            'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'open2day' ),
            'after'  => '</div>',
        ) );
    ?>
</div><!-- .entry-content -->

正如我所说,如果我用CSS删除标题,它也会删除内容。

请像下面这样在CSS中使用!important希望这将工作。

.entry-title {display:none !important;}

注释掉下面一行时:

<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>

你的页面不再有"entry-title"类的h1元素。

你的CSS期望这个元素在你的页面上,所以除非你想编辑你的CSS,你可以只添加以下空元素:

<h1 class="entry-title"></h1>

这应该可以解决你的问题,并允许内容在隐藏页面标题的同时显示。