使用wpseo_title和wpseo_metadesc重新排序标题标签和描述标签

时间:2018-06-20 17:30:06

标签: wordpress yoast

我正在尝试更改标题标签和描述标签(CMS Wordpress,插件Yoast SEO)的顺序。 现在,在页面代码中,它看起来像这样:

<title>something ...</title>
<meta name="description" content="something ..."/>

我想这样做:

<meta name="description" content="something ..."/>
<title>something ...</title>

我在function.php中尝试了此代码段,但是此代码无法正常工作

   add_filter( 'wpseo_title', '__return_false' );
   add_filter( 'wpseo_title', 'filter_wpseo_title', 90);
   add_filter( 'wpseo_metadesc', '__return_false' );
   add_filter( 'wpseo_metadesc', 'filter_wpseo_title', 10);

1 个答案:

答案 0 :(得分:0)

这是此示例,请尝试以下操作  我尝试通过页面ID更改页面元描述,解决方案是

    add_filter('wpseo_metadesc', function($description){
        global $post;
       $parent_post_id = wp_get_post_parent_id($post);
        $parent_post = get_post($parent_post_id);
        //$parent_post1 = get_children($parent_post_id);
        //echo "<pre>"; print_r($parent_post1->post_title); die();
        $parent_post_title = $parent_post->post_title;
        $name= get_the_title();

            if( is_page( array( 157, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 188, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216) ) ) {
                   $description = $name."post office locations listed alphabetically with complete temporary and permanent change of address assistance online.";
            }
            if( is_page( array( 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215) ) ) {
                   $description = $name."post office addresses alphabetically organized offering temporary and permanent address change assistance online.";
            }
            return $description;
});