Edit title-tag in wp_head with yoast seo

Question

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.com/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.com/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> &raquo; $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> &raquo; $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

0
, Wombat 2 years 2019-12-28T17:28:17-05:00 0 Answers 91 views 0

Leave an answer

Browse
Browse