0

I'm trying to change the order of the title tag and description tag (CMS Wordpress, plugin Yoast SEO). Now in the code of the page it looks like this:

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

And I want to do this:

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

I tried this snippet in function.php, but this code does not work correctly

   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);
4

1 回答 1

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;
});
于 2019-06-19T08:54:38.520 回答