WordPress 增加 keywords 和 description 。

<?php
	$keywords = '798资源网';
	$description = '798资源网';
	//文章页
	if (is_single()){
		//自定义栏目添加关键字和描述
		$single_keywords = get_post_meta($post->ID, "keywords", true);
		$description = get_post_meta($post->ID, "description", true);
		//如果没设置自定义关键字,将使用标签作为关键字
		if($single_keywords == ""){
			$tags = wp_get_post_tags($post->ID);
			foreach ($tags as $tag){
				$single_keywords = $single_keywords.$tag->name.",";
			}
			//去掉关键字前后的空白
			$single_keywords = rtrim($single_keywords, ', ');
		}
		///如果文章关键字不为空
		if($single_keywords){
			$keywords = $single_keywords;
		}
		//自定义描述如果为空,将使用文章中的100个字作为描述
		if($description == ""){
			if($post->post_excerpt){
				$description = $post->post_excerpt;
			}else{
				$description = mb_strimwidth(strip_tags(apply_filters('the_content',$post->post_content)),0,200);
			}
		}
	}
	//页面,添加自定义栏目keywords和description(关键字和描述)。
	elseif (is_page()){
		$keywords = get_post_meta($post->ID, "keywords", true);
		$description = get_post_meta($post->ID, "description", true);
	}
	//分类页,使用分类名作为关键字,分类描述作为文章描述。
	elseif (is_category()){
		$keywords = single_cat_title('', false);
		$description = category_description();
	}
	//标签页,使用标签名作为关键字,标签描述作为文章描述。
	elseif (is_tag()){
		$keywords = single_tag_title('', false);
		$description = tag_description();
	}
	//去掉两段空格
	$keywords = trim(strip_tags($keywords));
	$description = trim(strip_tags($description));
	?><meta name="keywords" content="<?php echo $keywords; ?>" />
	<meta name="description" content="<?php echo $description; ?>" />

WordPress 增加 keywords 和 description的更多相关文章

  1. wordpress模板里加keywords和description

    刚才我说了,wp会弄的话,功能是很强大的,插件很多,基本上你能想到的功能,插件都开发好了的.现在就来说说这个keywords和description的问题.我在网上找了些资料,总结一下,如果有引用到的 ...

  2. 正确设置网站title、keywords、description(转载)

    本文转载自蚂蚁HR(www.mayihr.com) 优化技巧是老师在课堂上教不了你的,而自己也不可能在练习中领悟,最便捷的方法就是听取别人的经验,所以转载一下 1.title(网站标题) title, ...

  3. discuz 门户页模板中的keywords和description不能正常显示

    最近用discuz搭建了一个素食网,在处理门户页模板时,发现虽然在后台的seo设置了keywords和description,但是以游客的身份访问时,不显示后台设置的内容,显示为: <meta ...

  4. xpath 获取meta里的keywords及description的方法

    html中的head的meta元素中的keywords与description标签如下: <meta name="keywords" content="xxxx&q ...

  5. 怎么WordPress增加在线投稿功能

    现在很多个人博客为了增加博客的内容,都会提供投稿通道,大部分都是以邮箱的形式进行投稿,不过这样一来,也很费人力,要拷贝复制,然后编辑等.如果给博客加个在线投稿功能,那就方便多了.稍微审核下文章内容就可 ...

  6. 怎样正确写网站title、keywords、description比较标准。

    一.title title,也就是标题,是在浏览器上面显示出来的,方便用户了解这个页面的内容;特别是搜索引擎判断你网页内容的主要根据.搜索引擎就很大部分是依靠网站title来判断你网站是关于什么内容的 ...

  7. 正确写网站title、keywords、description

    一.title title,也就是标题,是在浏览器上面显示出来的,方便用户了解这个页面的内容;特别是搜索引擎判断你网页内容的主要根据.搜索引擎就很大部分是依靠网站title来判断你网站是关于什么内容的 ...

  8. 页面关键词Meta Keywords和描述Description的优化作用

    前几日有两三个童鞋们问我为什么文章目录页面没有设置关键词,我原先还以为什么关键词,后来才明白是问我为什么不添加Meta Keywords.关于这个问题我直接回应他们说目录页面Meta Keywords ...

  9. SEO技巧之WordPress篇幅

    随着搜索引擎大兴, 排列在前的网站引入大量流量. 无论是搜索页面的广告还是查出来的结果, 与搜索者的目标匹配度都比较高 (如果搜索引擎足够智能), 所以通过搜索引擎而来的访客很可能会从网站上得到他想要 ...

随机推荐

  1. Win8 Windows Defender default behaviour

    Problem Description ********************* Is it possible, to change the default behaviour when findi ...

  2. NYOJ 71 独木舟上的旅行【贪心】

    解题思路:给出船的最大载重量w,和n个人,每只船最多可以乘坐两个人,问怎样坐船使得安排的船只的数量最少.这n个人的体重为a1,a2,a3,---,an-1,an首先将体重按升序排列好,再考虑最重的人, ...

  3. nginx 日志配置不生效的问题

    log_format 有个默认的日志格式: log_format combined '$remote_addr - $remote_user [$time_local] ' ' "$requ ...

  4. Pyhton学习——Day36

    #异步IO——Asynchronous#异步效率最高,特点:全程无阻塞# 在说明synchronous IO和asynchronous IO的区别之前,需要先给出两者的定义.# Stevens给出的定 ...

  5. adb屏幕截屏

    import subprocess #执行结果使用管道输出,对于参数是字符串,需要指定shell=Trueprocess = subprocess.Popen('adb shell screencap ...

  6. pytorch 6 batch_train 批训练

    import torch import torch.utils.data as Data torch.manual_seed(1) # reproducible # BATCH_SIZE = 5 BA ...

  7. Python 绘图与可视化 matplotlib 填充fill和fill_between

    参考链接:https://blog.csdn.net/You_are_my_dream/article/details/53457960 fill()填充函数曲线与坐标轴之间的区域: x = np.l ...

  8. windows下的ubuntu

    办公用Windows确实方便,但对于开发和学习还是用Linux比较好. 在Windows下安装Linux子系统 windows10中推出了Linux子系统,这个功能对开发和学习来说真的很好,非常方便. ...

  9. [luogu]P4365[九省联考]秘密袭击coat(非官方正解)

    题目背景 警告:滥用本题评测者将被封号 We could have had it all. . . . . . 我们本该,拥有一切 Counting on a tree. . . . . . 何至于此 ...

  10. Thunder9(迅雷9)去掉右侧浏览器广告的方法

    1.打开文件夹C:\Program Files (x86)\Thunder Network\Thunder9\Program\TBC 2.找到 ThunderBrowser.exe 3.重命名为任意名 ...