wordpress Woocommerce:如何删除标题中的“存档”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13075573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Woocommerce: How to remove "Archive" in title?
提问by MrRoman
I'm trying to remove the word "Archive" from the page title.
我正在尝试从页面标题中删除“存档”一词。
How to remove it? By adding a filter?
如何删除它?通过添加过滤器?
Example:
例子:
My collections Archive| My sitename
我的收藏档案| 我的站点名称
回答by Simon Kelly
Best to use Wordpress SEO by Yoast.
最好使用 Yoast 的 Wordpress SEO。
Within Titles & Metas go to the Taxonomies tab and update the Title template for Product Categories to remove the word Archive. Mine ended up looking like this:
在 Titles & Metas 中,转到 Taxonomies 选项卡并更新 Product Categories 的 Title 模板以删除单词 Archive。我的最终看起来像这样:
%%term_title%% %%page%% %%sep%% %%sitename%%
%%term_title%% %%page%% %%sep%% %%sitename%%
回答by Ted C
you can rewrite the filter in functions.php so it fails, causing WooCommerce not the render it.
您可以在functions.php 中重写过滤器,使其失败,从而导致WooCommerce 无法渲染它。
function override_page_title() {
return false;
}
add_filter('woocommerce_show_page_title', 'override_page_title');
回答by Stephan Muller
I know this is an old post but I tried the answers here and it didn't work. I found the solution basing it off renegadesk's answer, but in addition of going to the Taxonomies Tab I also had to change it in the Post Types tab. See below:
我知道这是一篇旧帖子,但我在这里尝试了答案,但没有奏效。我找到了基于 renegadesk 答案的解决方案,但除了转到分类法选项卡之外,我还必须在帖子类型选项卡中更改它。见下文:
Get Wordpress SEO by Yoast if you don't already have it, then click SEO > Titles & Metas > Post Types. Scroll down and look for the heading "Custom Post Type Archives". On the "Products", you can edit the content of this title. Mine now looks like this:
如果您还没有,请通过 Yoast 获取 Wordpress SEO,然后单击 SEO > 标题和元数据 > 帖子类型。向下滚动并查找标题“自定义帖子类型档案”。在“产品”中,您可以编辑该标题的内容。我的现在看起来像这样:
%%pt_plural%% %%page%% %%sep%% %%sitename%%
回答by Sergio Barbosa
If you are using the Yoast SEO (Versión 8.1.2), the options were move to:
如果您使用的是 Yoast SEO(版本 8.1.2),则选项将移至:
Yoast SEO -> Search Appearance -> Taxonomies.
Yoast SEO -> 搜索外观 -> 分类法。
In there look up by Product categories (product_cat) and open it.
在那里按产品类别(product_cat)查找并打开它。
Then remove the Archives string from the head.
然后从头部移除 Archives 字符串。
回答by Alexander Behling
in addition to Ted C:
除了泰德 C:
For this purpose Wordpress has already predifined functions starting with __return_. In this case the function you are looking for is __return_false.
为此,Wordpress 已经预先定义了以 __return_ 开头的函数。在这种情况下,您要查找的函数是 __return_false。
add_filter('woocommerce_show_page_title', '__return_false',10,0); will also work.
add_filter('woocommerce_show_page_title', '__return_false',10,0); 也会起作用。
The last two params are the order of the function and the number of params passed to it.
最后两个参数是函数的顺序和传递给它的参数数量。
It is always a good pratice to set them up but this is only necessary if you want to modify the default order (10) and the number of params passed (1).
设置它们总是一个好习惯,但只有当您想修改默认顺序 (10) 和传递的参数数量 (1) 时才需要这样做。
回答by Vincent Rocher
You have this filter for all cases : "get_the_archive_title". But then there are different cases.
您对所有情况都有此过滤器:“get_the_archive_title”。但也有不同的情况。
For exemple for simple category you can do :
例如,对于简单类别,您可以执行以下操作:
function prefix_category_title( $title ) {
if(is_category()){
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'prefix_category_title' );
For custom post type you should do :
对于自定义帖子类型,您应该执行以下操作:
function prefix_category_title( $title ) {
if(is_archive('slug-of-your-custom-post-type')){
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'prefix_category_title' );
So finally you have many condition like :
所以最后你有很多条件,比如:
- is_category
- is_archive
- is_tag
- is_author
- is_year
- is_tax
- is_category
- is_archive
- is_tag
- is_author
- is_year
- is_tax
https://developer.wordpress.org/reference/functions/get_the_archive_title/
https://developer.wordpress.org/reference/functions/get_the_archive_title/
Vincent.
文森特。
回答by Win
In woocommerce there seem to be 3 instances of Archives (case sensitive) one in \wp-content\plugins\woocommerce\woocommerce-hooks.php around line 50 and 2 in \wp-content\plugins\woocommerce\woocommerce-template.php around lines 240 ish Perhaps one of those is what you're looking for and you may be able to modify code.
在 woocommerce 中,似乎有 3 个档案(区分大小写)实例在 \wp-content\plugins\woocommerce\woocommerce-hooks.php 中的第 50 行和 \wp-content\plugins\woocommerce\woocommerce-template.php 中的第 2 行大约第 240 行 ish 也许其中之一就是您要查找的内容,并且您可以修改代码。
回答by sourcebreak
wp-content/plugins/woocommerce/templates/archive-product.php
wp-content/plugins/woocommerce/templates/archive-product.php
Edit this file archive-product.php and remove the below 3 lines.
编辑此文件 archive-product.php 并删除以下 3 行。
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
<?php endif; ?>
This will remove page title on shop page and all other pages.
这将删除商店页面和所有其他页面上的页面标题。