wordpress - Reorder title tag and description tag with wpseo_title and wpseo_metadesc
问题描述
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);
解决方案
这是这个的工作示例,请尝试这个我尝试通过页面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;
});
推荐阅读
- php - 发送电子邮件 codeigniter
- php - 如何使用 pdo 打印列值并根据行 ID 建立链接
- google-apps-script - 更新谷歌插件时遇到错误
- java - 安卓应用崩溃;登录错误:java.net.ConnectException:连接失败
- django - 请解释数据库如何与 django-rest-auth 和 get_user_model 一起使用
- apache - 客户端被服务器配置拒绝(htaccess;命令允许,拒绝)
- css - 图像 srcset 的语法有什么问题
- ada - Find factor of a number
- string - 是否可以在 SASS 的 @import 规则中使用变量?
- macos - NSPrintOperation 上下文总是 nil,导致崩溃。打印时如何设置上下文?