wordpress标题设置_如何隐藏选择性WordPress帖子和页面的标题

wordpress标题设置

In our post about how to hide widget titles, we had an interesting comment that presented a solution to hide title on selective single post and pages. We thought that it might be useful for some people. In this article, we will show you how to hide title for selective WordPress post and pages. We will also show you how to hide title of all WordPress posts and/or pages.

在有关如何隐藏小部件标题的帖子中,我们有一条有趣的评论,提出了一种在选择性的单个帖子和页面上隐藏标题的解决方案。 我们认为这对某些人可能有用。 在本文中,我们将向您展示如何隐藏WordPress选择性帖子和页面的标题。 我们还将向您展示如何隐藏所有WordPress帖子和/或页面的标题。

隐藏选择性文章和页面的标题 (Hide Titles for Selective Posts and Pages)

Do you want to hide titles for selective posts and pages without editing a single line of code? Then all you need to do is install and activate the Hide Title plugin for WordPress. After activation, go to the edit screen for the specific post and page. You can do this by simply clicking on the Posts or Pages menu in your WordPress admin and clicking on the item that you want to edit. On the edit screen, you will see a Hide Title meta box like this:

您是否要隐藏选择性帖子和页面的标题而无需编辑一行代码? 然后,您需要做的就是安装并激活WordPress的Hide Title插件。 激活后,转到特定帖子和页面的编辑屏幕。 您只需在WordPress管理员中单击“帖子”或“页面”菜单,然后单击要编辑的项目即可完成此操作。 在编辑屏幕上,您将看到“ 隐藏标题”元框,如下所示:

Hinding post or page title for single view pages

All you need to do is check this box and click on update or publish post button. That’s it. Now this plugin will hide the title on singular page views. What that means is that it will still show the title on your homepage or other archive pages, but not on the single page views. Open the post in the single post view to test the result to make sure that everything looks right.

您需要做的就是选中此框,然后单击“更新”或“发布帖子”按钮。 而已。 现在,此插件将在单个页面视图上隐藏标题。 这意味着它仍将在您的主页或其他存档页面上显示标题,而不在单个页面视图上显示。 在单个帖子视图中打开帖子以测试结果,以确保一切正常。

This solution can be pretty handy if you are creating a simple landing page and you don’t want to show the title.

如果您要创建一个简单的着陆页并且不想显示标题,则此解决方案可能非常方便。

隐藏所有WordPress帖子和页面的标题 (Hide Titles for All WordPress Posts and Pages)

We can’t think of a reason why someone would do this, but lets look at how to hide the titles for all WordPress post and pages for the sake of learning. If for some reason, you want to hide title for all posts and pages on single pages, then you can achieve this by editing your theme. There are few ways of doing this.

我们无法想到有人会这样做的原因,但是让我们看看如何为了所有学习目的而隐藏所有WordPress帖子和页面的标题。 如果出于某种原因想要隐藏单个页面上所有文章和页面的标题,则可以通过编辑主题来实现。 这样做的方法很少。

The easiest solution would be add this code to your WordPress theme’s functions.php file.

最简单的解决方案是将此代码添加到WordPress主题的functions.php文件中。


function wpb_hidetitle_class($classes) {
if ( is_single() || is_page() ) : 
$classes[] = 'hidetitle';
return $classes;
endif; 
return $classes;
}
add_filter('post_class', 'wpb_hidetitle_class');

This filter simply adds an extra class .hidetitle to the post_class() function only when a single post or page is displayed. However, this filter will only work if your WordPress theme has support for the post class. If you want to do this for posts only and not pages, then just get rid of the part || is_page().

仅当显示单个帖子或页面时,此过滤器仅向post_class()函数添加一个额外的类.hidetitle 。 但是,仅当您的WordPress主题支持post类时,此过滤器才起作用。 如果您只想对帖子而不是对页面进行此操作,则只需删除|| is_page()部分即可。 || is_page()

After adding this function, you need to add this css rule into you theme’s stylesheet.

添加此功能后,您需要将此css规则添加到主题的样式表中。


.hidetitle .entry-title { 
display:none;
}

In the above CSS we have used display css property to hide the post and page title. However this CSS rule will only work if your WordPress theme uses entry-title in the post or page title. To find out which CSS class your theme uses for post titles, simply open your post in Google Chrome or Mozilla Firefox and take your mouse over to post title. Right click and select Inspect Element. Your browser will split up and you will see page source highlighting the source code for post title where you can see the CSS class used by your theme.

在上面CSS中,我们使用了display css属性来隐藏帖子和页面标题。 但是,仅当您的WordPress主题在帖子或页面标题中使用条目标题时,此CSS规则才有效。 要找出主题用于帖子标题CSS类,只需在Google Chrome或Mozilla Firefox中打开您的帖子,然后将鼠标移到帖子标题上即可。 右键单击并选择检查元素。 您的浏览器将拆分,您将看到页面源代码,突出显示帖子标题的源代码,您可以在其中查看主题使用CSS类。

Finding CSS class used for an element

Lets assume that your theme uses article-title as CSS class for post titles. Simply change the CSS like this:

假设您的主题使用article-title作为帖子标题CSS类。 只需像这样更改CSS:


.hidetitle .article-title { 
display:none; 
}

The reason why we say that the above solution is the easiest one is because it will work for child themes of popular theme frameworks like Genesis and others. It will also work just fine for standalone WordPress themes.

我们之所以说上述解决方案最简单,是因为它适用于诸如Genesis等流行主题框架的子主题。 它也适用于独立的WordPress主题。

Now both of the solutions that we have mentioned above will hide the title, but they are still loading the titles. So in other words, they are hiding it but not removing it. If you are a theme designer or someone who wants to remove the post or page title from your template, then you need to remove the_title code from appropriate theme files.

现在,我们上面提到的两个解决方案都将隐藏标题,但是它们仍在加载标题。 因此,换句话说,他们正在隐藏而不是删除它。 如果您是主题设计师,或者想从模板中删除帖子或页面标题,则需要从适当的主题文件中删除the_title代码。

If you only want to do this for single post views, then you will likely find this code located in your single.php file. However, if you want to do this for through out the site, then you will need to edit files like index.php, archive.php, single.php, and any other file that contains a loop basically. It will require trial and error if you are new to this.

如果只想对单个帖子视图执行此操作,则可能会在single.php文件中找到此代码。 但是,如果要在整个站点中执行此操作,则需要编辑index.php,archive.php,single.php等文件,以及其他基本上包含循环的文件。 如果您是新手,则需要反复试验。

If you are working with one of the theme frameworks, then you would want to stick with the plugin solution or the post_class solution that we showed you.

如果您使用的是主题框架之一,那么您将希望坚持使用我们向您展示的插件解决方案或post_class解决方案。

We hope that this article helped you hide the title for specific WordPress posts and pages. What possible use cases can you see where you would want to hide post or page titles in single views? Let us know by leaving a comment below.

我们希望本文能帮助您隐藏特定WordPress帖子和页面的标题。 您可以看到哪些可能的用例在单个视图中隐藏帖子或页面标题的位置? 让我们在下面留下评论。

翻译自: https://www.wpbeginner.com/plugins/how-to-hide-post-and-page-titles-in-wordpress-single-pages/

wordpress标题设置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值