元标记代码正在打破并显示在WordPress网站中

发布于 2025-01-23 18:44:20 字数 1847 浏览 3 评论 0原文

我正在使用以下代码来自动化我的帖子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');

问题是: 在某些帖子中,代码正在打破元标记代码,而发生的事情是该帖子的第一段的一部分出现在网站顶部(标题)。这是我得到的输出:

<meta property="fb:app_id" content="1667889836683276" /><meta property="og:title" content="+ de 180 Sites &#038; 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"/>

这并不是每个帖子中都会发生的。这是它发生的页面之一: https://lucrebem.com。 br/emp-digital/ferramentas-seo/

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/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文