wordpress自定义字段插件

wordpress自定义字段插件

浏览次数:
信息来源: 用户投稿
更新日期: 2025-09-30 19:03:43
文章简介

wordpress我们尽量不用插件就不用插件太多会拖慢速度,当我们在拿到WordPress程序部署网站之后,大部分是需要设置首页标题、描述和关键字,这样适应用户对于标题

2025阿里云双十一服务器活动

wordpress我们尽量不用插件就不用插件太多会拖慢速度,当我们在拿到WordPress程序部署网站之后,大部分是需要设置首页标题、描述和关键字,这样适应用户对于标题的自定义需要。默认情况下,WP自带的标题是不具备这样的功能,我们一般可以采用插件实现,用的较多的是AllinOneSEOPack以及WPSEOTDK插件都可以实现,这两个插件还是不错的。但是我们不要插件来实现这个功能看看!

上午在整理电脑桌面的时候,看到之前一段时间给一个企业网站设置标题的时候用的无插件设置方式,这里正好做一个备份,以便以后有需要用到,这个也是从网上找过来的。

<?phpif(is_home()){?><title>自定义设置一个首页标题</title><?php}?>

<?phpif(is_search()){?><title>搜索结果|<?phpbloginfo('name');?></title><?php}?>

<?phpif(is_single()){?><title><?phpechotrim(wp_title('',0));?>|<?phpbloginfo('name');?></title><?php}?>

<?phpif(is_page()){?><title><?phpechotrim(wp_title('',0));?>|<?phpbloginfo('name');?></title><?php}?>

<?phpif(is_category()){?><title><?phpsingle_cat_title();?>|<?phpbloginfo('name');?></title><?php}?>

<?phpif(is_month()){?><title><?phpthe_time('F');?>|<?phpbloginfo('name');?></title><?php}?>

<?phpif(function_exists('is_tag')){if(is_tag()){?><title><?php?single_tag_title("",true);?>|<?phpbloginfo('name');?></title><?php}?><?php}?>

if(!function_exists('utf8Substr')){

functionutf8Substr($str,$from,$len)

returnpreg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.

'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s',

if($post->post_excerpt){

wordpress自定义字段插件

if(preg_match('/<p>(.*)</p>/iU',trim(strip_tags($post->post_content,"<p>")),$result)){

$post_content=$result['1'];

$post_content_r=explode("

",trim(strip_tags($post->post_content)));

$post_content=$post_content_r['0'];

$description=utf8Substr($post_content,0,220);

$tags=wp_get_post_tags($post->ID);

$keywords=$keywords.$tag->name.",";

<?phpif(is_single()){?>

<metaname="description"content="<?phpechotrim($description);?>"/>

<metaname="keywords"content="<?phpechortrim($keywords,',');?>"/>

<?phpif(is_home()){?>

<metaname="description"content="网站首页描述内容"/>

这里我们可以将上面的代码另外title.php页面,当然需要将两处标注红色的文字修改成自己网站首页的描述和标题,如果有需要设置关键字的,也可以在最后添加一行。

<?phpinclude('title.php');?>

我们还需要修改当前WP主题重点讹Header.php文件原来的title标签部分,替换上面一行。基本上可以满足大部分主题的使用,有些特殊的主题是无效的。

标签:
CubeCloud香港HKBN少量有货(cloudcone香港)
« 上一篇
返回列表
下一篇 »

如本文对您有帮助,就请抽根烟吧!