虽然我们都知道\\”All in One SEO Pack\\”插件是可以自动且自定义设置文章的关键字(keyword)、描述(description)的,但是有些时候能精简的就尽量的精简。这里蜗牛看到一个办法可以快速且自动的给每篇文章设置自动描述。
function wp_auto_desc() {
global $post;
if (!is_single()) { return; }
$meta = strip_tags($post->post_content);
$meta = strip_shortcodes($post->post_content);
$meta = str_replace(array(\\”\\\\n\\”, \\”\\\\r\\”, \\”\\\\t\\”), \\’ \\’, $meta);
$meta = substr($meta, 0, 300);//数字300可以自己调整
echo \\”<meta name=\\’description\\’ content=\\’$meta\\’ />\\”;
}
add_action(\\’wp_head\\’, \\’wp_auto_desc\\’);
我们可以将脚本添加到当前主题的Functions.php文件中,其中默认是300字符长度,我们可以根据需要调整长度。
评论前必须登录!
立即登录 注册