admin管理员组文章数量:1377563
I want to manipulate the html-title tag, so <title>
these not the content of the title-tag!
I use child-themes and it's inevitable, because the template have to be easy to update. So I have to use the functions.php or the header.php in the child-folder.
At moment I try it with the functions.php
At moment I have following situation:
<!-- Start WP_HEAD
================================================== -->
<!-- This site is optimized with the Yoast WordPress SEO plugin v1.5.3.3 - / -->
<title>My awesome title-content</title>
<meta name="robots" content="noindex,follow,noodp,noydir"/>
<link rel="canonical" href="WEBSITE" />
<meta property="og:locale" content="de_DE" />
and I want to have these situation:
The focus are on the title-tag
<!-- Start WP_HEAD
================================================== -->
<!-- This site is optimized with the Yoast WordPress SEO plugin v1.5.3.3 - / -->
<title itemprop="name" id="company_name">My awesome title-content</title>
<meta name="robots" content="noindex,follow,noodp,noydir"/>
<link rel="canonical" href="WEBSITE" />
<meta property="og:locale" content="de_DE" />
my current try in the functions.php in the child-folder are:
add_action('get_header', 'blog_template_add_ob_start');
add_action('wp_head', 'blog_template_add_ob_end_flush', 100);
function blog_template_add_ob_start() {
ob_start('blog_template_add_filter_wp_head_output');
}
function blog_template_add_ob_end_flush() {
ob_end_flush();
}
function blog_template_add_filter_wp_head_output($output) {
if (is_single()) {
$output = preg_replace('/<title>(.*?) - (.*?)<\/title>/', '<title><span itemprop="name" id="company_name">$2</span> » $1</title>', $output);
#$output = str_ireplace('<meta property="og:url" content="' . $url . '" />', '<meta property="og:url" content="' . esc_attr(esc_url($altUrl)) . '" />', $output);
}
return $output;
}
my first try was these: first:
function add_itempromp_to_title( $str )
{
#$str = preg_replace('/<title>(.*?) - (.*?)<\/title>/', '<title><span itemprop="name" id="company_name">$2</span> » $1</title>', $str);
return $str;
}
add_filter( 'wp_head', 'add_itempromp_to_title', 99 );
I had try these: Manipulating wp_head content but isn't work anymore.
Does anyone have an idea?
The Yoast-Plugin-Version are 1.5.3.3
The WP-Version are 3.8.3
I want to manipulate the html-title tag, so <title>
these not the content of the title-tag!
I use child-themes and it's inevitable, because the template have to be easy to update. So I have to use the functions.php or the header.php in the child-folder.
At moment I try it with the functions.php
At moment I have following situation:
<!-- Start WP_HEAD
================================================== -->
<!-- This site is optimized with the Yoast WordPress SEO plugin v1.5.3.3 - https://yoast/wordpress/plugins/seo/ -->
<title>My awesome title-content</title>
<meta name="robots" content="noindex,follow,noodp,noydir"/>
<link rel="canonical" href="WEBSITE" />
<meta property="og:locale" content="de_DE" />
and I want to have these situation:
The focus are on the title-tag
<!-- Start WP_HEAD
================================================== -->
<!-- This site is optimized with the Yoast WordPress SEO plugin v1.5.3.3 - https://yoast/wordpress/plugins/seo/ -->
<title itemprop="name" id="company_name">My awesome title-content</title>
<meta name="robots" content="noindex,follow,noodp,noydir"/>
<link rel="canonical" href="WEBSITE" />
<meta property="og:locale" content="de_DE" />
my current try in the functions.php in the child-folder are:
add_action('get_header', 'blog_template_add_ob_start');
add_action('wp_head', 'blog_template_add_ob_end_flush', 100);
function blog_template_add_ob_start() {
ob_start('blog_template_add_filter_wp_head_output');
}
function blog_template_add_ob_end_flush() {
ob_end_flush();
}
function blog_template_add_filter_wp_head_output($output) {
if (is_single()) {
$output = preg_replace('/<title>(.*?) - (.*?)<\/title>/', '<title><span itemprop="name" id="company_name">$2</span> » $1</title>', $output);
#$output = str_ireplace('<meta property="og:url" content="' . $url . '" />', '<meta property="og:url" content="' . esc_attr(esc_url($altUrl)) . '" />', $output);
}
return $output;
}
my first try was these: first:
function add_itempromp_to_title( $str )
{
#$str = preg_replace('/<title>(.*?) - (.*?)<\/title>/', '<title><span itemprop="name" id="company_name">$2</span> » $1</title>', $str);
return $str;
}
add_filter( 'wp_head', 'add_itempromp_to_title', 99 );
I had try these: Manipulating wp_head content but isn't work anymore.
Does anyone have an idea?
The Yoast-Plugin-Version are 1.5.3.3
The WP-Version are 3.8.3
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Jun 24, 2014 at 18:53 WombatWombat 311 silver badge2 bronze badges 6- Your Approach will NEVER WORK. A span tag is not allowed in the Title Tag. Only Text is allowed in the Title Tag. Meta Tags and Script Tags along with the Title Tag in the Head Section. See How to Write Title Tags For Search Engine Optimization – eyoung100 Commented Jun 24, 2014 at 19:34
- You might be able to add this as a meta tag, but I'm assuming you want to use it for some purpose in WordPress, plus the search engine will crawl the meta tag for help in indexing the site. – eyoung100 Commented Jun 24, 2014 at 19:46
- okay, but this solve not the mainproblem, that I can't manipulate the generated head of yoast plugin. Now I try to edit a meta-tag with the same result, it doesn't work. – Wombat Commented Jun 24, 2014 at 20:02
- First of all, what are you trying to accomplish by editing the head section? I think I know what you're trying to do, but I want clarification before I give you an approach. – eyoung100 Commented Jun 24, 2014 at 20:08
- after I have read your comment I change my idea of editing the title-tag. But now the idea is to manipulate the og:site-meta tag, that also be add by the yoast seo plugin. So I want add to this meta-tag a itemprop. As I know is this compatible with the wc3-standard. – Wombat Commented Jun 25, 2014 at 23:58
2 Answers
Reset to default 2I don't think adding <span itemprop>
to the <title>
is a good idea... If you can not use any existing tags like <h1>
for that, you may consider adding meta
tag: <meta itemprop="name" content="Company Name">
. You can add this using wp_head, but keep in mind it should be within itemscope
.
If you really going after changing title
tag, Yoast SEO has it's own filter 'wpseo_title', so you need to call that one.
add_filter('wpseo_title', 'filter_title');
function filter_title($title) {
// do something to the $title here
return $title;
}
I still don't know why you're trying to pass the item property through the head tag. I have a gut feeling you're trying to tell Google abut a particular item. For example:
- itemprop is brown_shoes
- itemprop is red_hat
In each of these cases, you want Google to know that you sell brown shoes or a red hat.
This would be better suited if you created a wp_products table in your database, and in that table, put the following:
- product_id - This will be the Primary Key
- product_desc - Description
- product_image - URL to image
- product_price - Price
- product_keywords - These will be keywords that you can pass to the meta tag
Create a ProductPage Template, using a Custom WP_Query and this Plugin, URL Params, to pass the product_id
field to every page. In the HEAD SECTION of the template add:
<meta name="keywords" content="<? php echo $product_keywords; ?>"
Since PHP completes the WP_Query before rendering the page, this is perfectly acceptable.
本文标签: wp headEdit titletag in wphead with yoast seo
版权声明:本文标题:wp head - Edit title-tag in wp_head with yoast seo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744489523a2608651.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论