WordPress无插件实现标题、关键字、描述自定义设置
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

一般,我们在拿到WordPress程序部署网站之后,大部分是需要设置首页标题、描述和关键字,这样适应用户对于标题的自定义需要。默认情况下,WP自带的标题是不具备这样的功能,我们一般可以采用插件实现,用的较多的是All in One SEO Pack以及前一段时间蜗牛有分享的WP SEO TDK插件都可以实现。
上午在整理电脑桌面的时候,看到之前一段时间给一个企业网站设置标题的时候用的无插件设置方式,这里正好做一个备份,以便以后有需要用到,这个也是从网上找过来的。
第一、全部代码
<?php if ( is_home() ) { ?><title>自定义设置一个首页标题</title><?php } ?>
<?php if ( is_search() ) { ?><title>搜索结果 – <?php bloginfo(\’name\’); ?></title><?php } ?>
<?php if ( is_single() ) { ?><title><?php echo trim(single_post_title(\’\’)); ?> – <?php bloginfo(\’name\’); ?></title><?php } ?>
<?php if ( is_page() ) { ?><title><?php echo trim(get_the_title(\’\’)); ?> – <?php bloginfo(\’name\’); ?></title><?php } ?>
<?php if ( is_category() ) { ?><title><?php single_cat_title(); ?> – <?php bloginfo(\’name\’); ?></title><?php } ?>
<?php if ( is_month() ) { ?><title><?php the_time(\’F\’); ?> – <?php bloginfo(\’name\’); ?></title><?php } ?>
<?php if (function_exists(\’is_tag\’)) { if ( is_tag() ) { ?><title><?php single_tag_title(\”\”, true); ?> – <?php bloginfo(\’name\’); ?></title><?php } ?> <?php } ?>
<?php
if (!function_exists(\’utf8Substr\’)) {
function utf8Substr($str, $from, $len)
{
return preg_replace(\’#^(?:[\\x00-\\x7F]|[\\xC0-\\xFF][\\x80-\\xBF]+){0,\’.$from.\’}\’.
\'((?:[\\x00-\\x7F]|[\\xC0-\\xFF][\\x80-\\xBF]+){0,\’.$len.\’}).*#s\’,
\’$1\’,$str);
}
}
if ( is_single() ){
if ($post->post_excerpt) {
$description = $post->post_excerpt;
} else {
if(preg_match(\’/<p>(.*)<\\/p>/iU\’,trim(strip_tags($post->post_content,\”<p>\”)),$result)){
$post_content = $result[\’1\’];
} else {
$post_content_r = explode(\”\\n\”,trim(strip_tags($post->post_content)));
$post_content = $post_content_r[\’0\’];
}
$description = utf8Substr($post_content,0,220);
}
$keywords = \”\”;
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag ) {
$keywords = $keywords . $tag->name . \”,\”;
}
}
?>
<?php echo \”\\n\”; ?>
<?php if ( is_single() ) { ?>
<meta name=\”description\” content=\”<?php echo trim($description); ?>\” />
<meta name=\”keywords\” content=\”<?php echo rtrim($keywords,\’,\’); ?>\” />
<?php } ?>
<?php if ( is_home() ) { ?>
<meta name=\”description\” content=\”网站首页描述内容\” />
<?php } ?>
这里我们可以将上面的代码另外title.php页面,当然需要将两处标注红色的文字修改成自己网站首页的描述和标题,如果有需要设置关键字的,也可以在最后添加一行。
第二、引用修改
<?php include(\’title.php\’); ?>
我们还需要修改当前WP主题重点讹Header.php文件原来的title标签部分,替换上面一行。基本上可以满足大部分主题的使用,有些特殊的主题是无效的。
猜你可能想看的VPS
- SpartanHost→西雅图 KVM 月付 2 美元起 大硬盘 VPS全球[VPS测评]
- 四个倒着的脚字是什么成语?全球[VPS测评]
- 飞飞 cms 网站搬家后如何设置数据库配置信息 飞飞 cms 数据库配置全球[VPS测评]
- 推荐 iON→KT 旗下品牌 CN2 线路 洛杉矶机房 全场限时 5 折全球[VPS测评]
- 劳动节 vpsyc→6 折优惠 美国 cn2 gia VPS 200Mb美国VPS[主机]
- 预售 UOvZ→HK-CMI 预售版 1G 套餐年付$22.49 1G 全球[VPS测评]
- Zcloudme→$59.5 月 2*E5-2620v3 32G 内存 香港VPS[主机]
- 不限流量 $5 月 2G 内存 50G SSD 1Gbps 不限流量 K全球[VPS测评]
- 便宜 cloudcone 最新促销→1 核 512M 内存 10G 硬盘全球[VPS测评]
- 使用测速脚本对国外VPS服务器进行测速全球[VPS测评]
- Redis、Opcache对WordPress实现内存级缓冲优化全球[VPS测评]
- 日本VPS服务器商家收集汇总 方便购买日本VPS服务器日本VPS[主机]
- hostodo美国便宜VPS,1.5G内存,8T超大流量,1Gbps带宽美国VPS[主机]
- QuadraNet机房洛杉矶便宜服务器,E3处理器,30TB大流量, $全球[VPS测评]
- RenkliHost → 土耳其 7折优惠 年付15$ 1C1G15G硬全球[VPS测评]
- Joodle-3$ 月 南非VPS 原生ip 1核1G30G硬盘 1Gb全球[VPS测评]
- WikiHost 洛杉矶INAP线路VPS 可NF HULU全球[VPS测评]
- PacificRack → 512M 25G SSD 500G $12.全球[VPS测评]
- 为什么大家都选择香港服务器建站香港VPS[主机]
- 8K超高清记录中国空间站凌月:天和核心舱与问天实验舱组成“土”字结构虚拟空间(主机)
- 详细介绍vps云服务器及其作用全球[VPS测评]
- 消费复苏形势良好,我们将多措并举实施扩大内需政策全球[VPS测评]
- 酷锐云双十一活动:美国vps、香港vps云主机,2核4G4M,50元/首美国VPS[主机]
- 2022年有哪些顶级托管服务提供商全球[VPS测评]
- 阿里云香港服务器价格优惠:老用户香港2核4G3M云服务器仅1181.5元香港VPS[主机]
- 柚子互联:美国洛杉矶CN2 vps,防御100G/带宽10M,28元/月美国VPS[主机]
- 桔子数据怎么样?美国、香港CN2云服务器2核2G10M带宽仅480元/年美国VPS[主机]
- 30个美容院抖音唯美文案,看到就直接拿去发吧全球[VPS测评]
- 亿速云双12年终回馈:云服务器2折活动,订单满100元减50元全球[VPS测评]
- TmhHost优惠码:黑五优惠全场8折,洛杉矶vps、日本CN2、韩国C日本VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-39364.html











