'Meta tag code is breaking and showing in wordpress site's header
I'm using the following code to autogenerate my posts metatags:
function gretathemes_meta_description() {
global $post;
if ( is_singular() ) {
$des_post = strip_tags( $post->post_content );
$des_post = strip_shortcodes( $post->post_content );
$des_post = str_replace( array("\n", "\r", "\t"), ' ', $des_post );
$des_post = mb_substr( $des_post, 0, 300, 'utf8' );
print '<meta name="description" content="' . $des_post . '" />' . "\n";
}
if ( is_home() ) {
print '<meta name="description" content="' . get_bloginfo( "description" ) . '" />' . "\n";
}
if ( is_category() ) {
$des_cat = strip_tags(category_description());
print '<meta name="description" content="' . $des_cat . '" />' . "\n";
}
}
add_action( 'wp_head', 'gretathemes_meta_description');
function gretathemes_meta_tags() {
print '<meta name="meta_name" content="meta_value" />';
}
add_action('wp_head', 'gretathemes_meta_tags');
The problem is: In some posts that code is breaking the meta tag code, and what's happening is that part of the first paragraph of the post is showing up on the top of the website (header). This is the output that I'm getting:
<meta property="fb:app_id" content="1667889836683276" /><meta property="og:title" content="+ de 180 Sites & Ferramentas de SEO [2022]: A lista definitiva (Revisados e Avaliados)"/><meta property="og:type" content="article"/><meta property="og:url" content="https://lucrebem.com.br/emp-digital/ferramentas-seo/"/><meta property="og:site_name" content="Lucre Bem"/><meta property="og:image" content="https://lucrebem.com.br/wp-content/uploads/2015/12/office-620817_960_7201-300x199.jpg"/>
This does not happen in every post. This is one of the pages where it is happening: https://lucrebem.com.br/emp-digital/ferramentas-seo/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
