admin管理员组文章数量:1316854
Firstly, add_theme_support( 'title-tag' );
is enabled in my theme.
I have two filters to modify titles, this one hooking on to the_title
add_filter( 'the_title', 'custom_account_endpoint_titles', 10, 2 );
function custom_account_endpoint_titles( $title ) {
// Currently only have conditions here for My Account pages (is_account_page())
// example: if ( isset( $wp_query->query_vars['edit-account'] ) && is_account_page() ) {
return $title;
}
Secondly I have another function which fixed some title issues on Account pages as well (if I do not add this, the My Account pages all revert to a title tag of simply My Account
instead of the conditional statements set for the Title changed intended.
function theme_slug_filter_wp_title( $title_parts ) {
$title_parts['title'] = get_the_title();
return $title_parts;
}
add_filter( 'document_title_parts', 'theme_slug_filter_wp_title' );
Doing a little debugging -- adding a print_r
on $title_parts
in the document_title_parts
function
<pre>Array
(
[title] => Products
[site] => Example
)
</pre>
One would think, that the Title on my Shop Archive page would just be Products
, but that is not the case.
Doing the same print_r
debugging on the the_title
filter on my shop archive page...
brings back <pre>925 Sterling Silver.....</pre>
(which is the name of the first product in the loop
followed by <pre>Shop</pre>
for the breadcrumb
and then additionally above all my products in the shop archive, the title and a list of classes, but te html seems to be malformed when doing so which is odd:
<div class="grid_col"> <div <pre="">925 Sterling Silver...... class="shop-product hover-border nt-post-class masonry-item excerpt-none product type-product "
The only solution I have read which does not work is hooking onto the is_shop()
function in my the_title
filter, such as..
add_filter( 'the_title', 'custom_account_endpoint_titles', 10, 2 );
function custom_account_endpoint_titles( $title ) {
global $wp_query;
global $current_user;
if (is_shop()) {
return 'My Shop Archive';
}
This does indeed change the <title>
tag on the shop page to My Shop Archive
... but then proceeds to change the title of all my products on the page to My Shop Archive
!
What is the solution for just simply changing the <title>
tag on my shops archive page without affecting the product titles like in the image above?
Firstly, add_theme_support( 'title-tag' );
is enabled in my theme.
I have two filters to modify titles, this one hooking on to the_title
add_filter( 'the_title', 'custom_account_endpoint_titles', 10, 2 );
function custom_account_endpoint_titles( $title ) {
// Currently only have conditions here for My Account pages (is_account_page())
// example: if ( isset( $wp_query->query_vars['edit-account'] ) && is_account_page() ) {
return $title;
}
Secondly I have another function which fixed some title issues on Account pages as well (if I do not add this, the My Account pages all revert to a title tag of simply My Account
instead of the conditional statements set for the Title changed intended.
function theme_slug_filter_wp_title( $title_parts ) {
$title_parts['title'] = get_the_title();
return $title_parts;
}
add_filter( 'document_title_parts', 'theme_slug_filter_wp_title' );
Doing a little debugging -- adding a print_r
on $title_parts
in the document_title_parts
function
<pre>Array
(
[title] => Products
[site] => Example
)
</pre>
One would think, that the Title on my Shop Archive page would just be Products
, but that is not the case.
Doing the same print_r
debugging on the the_title
filter on my shop archive page...
brings back <pre>925 Sterling Silver.....</pre>
(which is the name of the first product in the loop
followed by <pre>Shop</pre>
for the breadcrumb
and then additionally above all my products in the shop archive, the title and a list of classes, but te html seems to be malformed when doing so which is odd:
<div class="grid_col"> <div <pre="">925 Sterling Silver...... class="shop-product hover-border nt-post-class masonry-item excerpt-none product type-product "
The only solution I have read which does not work is hooking onto the is_shop()
function in my the_title
filter, such as..
add_filter( 'the_title', 'custom_account_endpoint_titles', 10, 2 );
function custom_account_endpoint_titles( $title ) {
global $wp_query;
global $current_user;
if (is_shop()) {
return 'My Shop Archive';
}
This does indeed change the <title>
tag on the shop page to My Shop Archive
... but then proceeds to change the title of all my products on the page to My Shop Archive
!
What is the solution for just simply changing the <title>
tag on my shops archive page without affecting the product titles like in the image above?
1 Answer
Reset to default 0Seems like the solution I was looking for was !in_the_loop()
Full:
add_filter( 'the_title', 'custom_account_endpoint_titles', 10, 2 );
function custom_account_endpoint_titles( $title ) {
if (is_shop() && !in_the_loop() && ! is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX )) {
return 'Shop - Parure.co';
}
}
Note: the !is_admin
and !DOING_AJAX
functions are to prevent this from affecting product titles in the admin panel
本文标签:
版权声明:本文标题:woocommerce offtopic - Changing Title Tag on Shop Archive Page (current solution reverting to Title of First Product in Loop) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742009959a2412703.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论