我目前在wordpress中使用条件元标记代码。 一切工作正常,除了在某些页面上。WordPress的条件元标记说明
代码的header.php:在functions.php的
<meta name="description" content="<?php echo metadesc($post->ID); ?>" />
<?php }else{ ?>
<meta name="description" content="<?php bloginfo('description'); ?>" />
<?php } ?>
代码:
function metadesc($pid) {
$p = get_post($pid);
$description = strip_tags($p->post_content);
$description = str_replace ("\n","",$description);
$description = str_replace ("\r","",$description);
if (strlen($description) > 135) {
return htmlspecialchars(substr($description,0,135) . "...");
}else{
return htmlspecialchars($description);
}
}
这是它显示了当我去源,并期待在对元标记描述以下页面:
家:(在Wordpress常规设置中定义的主页描述(支票)
传记:页面(检查)的第135个字符
联系人:
<meta name="description" content="[contact-form-7 id="25" title="Contact"]" />
正如你所看到的,我只有我的联系页面上的联系表,它看起来像我需要添加一个过滤到脚本,以便它忽略脚本标记和短代码,并且它会替代地放置主页描述。
我该如何解决这个问题?
我把你的脚本替换成了我的,但后来出现语法错误 – Eric
你把家里的内容放在**返回中请得到主页的内容**和你得到了什么语法错误 –
是的,没有语法错误了,但没有变化,仍然: – Eric