WordPress前期怎么做好网站标题描述

海外服务器 (523) 2015-12-01 14:50:49

做网站做SEO的朋友都知道,好的排名和标题是分不开的,关键词好排名好自然能给你带来源源不断的流量,互联网是一个资源共享的服务社区,标题描述甚至关键词的相似度很高。我们怎么才能做到自己网站和别人的设置不同?这个就是做网站前期应该准备工作了。

WordPress网站模版对于网站标题、关键词、描述做的都不是很好。需要自己单独的设置调整。wordpress调用模版程序很是方面我们在设置网站关键的时候可以从模版程序header.php入手主要调整title,description,keywords几个关键词的显示方式。

1.现在来看下我是怎么设置模版的标题获取方式的:

<title><?php if ( is_home() ) { ?><?php bloginfo(’name’); ?><?php } ?>//网站首页

<?php if ( is_search() ) { ?>搜索到”<?php echo $s; ?>”_<?php bloginfo(‘name’); ?><?php } ?>//

<?php if ( is_404() ) { ?>404页面_<?php bloginfo(‘name’); ?><?php } ?>//

<?php if ( is_single() ) { ?><?php echo trim(wp_title(”,false)); ?>_<?php foreach((get_the_category()) as $category) {  echo $category->cat_name;

 } ?>xxxxxxx<?php } ?>//文章页面标题设置

</title>

这个就是网站首页,搜索页面、404页面标题、内容页面的设置方式,使用if语句达到选择的目的了,而不会像有的模版的网站首页,列表页基本没什么区别,其实if语句让我们让我们拥有更多的选择设置,网站的列表页,归档类,标签页面都是可以用同样的方式扩展,方便快捷。

2.网站的标题必不可少的一个设置步骤,其实网站的描述关键词也是需要设置才能更加完善,手动设置才能获得网页发挥的最大效果。现在来看下小编怎么设置网站描述关键词的获取方式。

<?php

if (is_home())//首页关键字和描述,可以换成你网站的

{

$description = “xxxxx”;

$keywords = “xxxx”;

$description = trim(strip_tags($description));

$keywords = trim(strip_tags($keywords));

echo “<meta name=\”description\” content=\”$description\” />//显示该页面的描述关键词

<meta name=\”keywords\” content=\”$keywords\” />”;
}

elseif (is_page())//单独页面关键字和描述,WordPress默认是不显示的,考虑到单独页面也不多,这种判断形式还算快速,只要取得页面对应ID即可

{

if ($post->ID >= 1)//数字1是页面的ID,查看方法:鼠标移至对应页面的“编辑”字样上,状态栏出现的链接,形如post.php?post=1&action=edit,其中post=后面的数字1就是对应页面ID

{

$description = substr(strip_tags($post->post_content),0,220);

//$description = “但页面信息描述”;

$keywords = “xxxx”;

}

$description = trim(strip_tags($description));

$keywords = trim(strip_tags($keywords));

echo “<meta name=\”description\” content=\”$description\” />

<meta name=\”keywords\” content=\”$keywords\” />”;

}

elseif (is_single())//文章页关键字和描述

{

if ($post->post_excerpt) {

$description = $post->post_excerpt;

} else {

$description = substr(strip_tags($post->post_content),0,220);

}

$keywords = get_post_meta($post->ID, “keywords”, true);//注意,这里调用的是文章的“自定义栏目”,不是文章TAG标签。你可以添加一个名称为“keywords”的自定义栏目作为每篇文章的关键字(keywords)

$description = trim(strip_tags($description));

$keywords = trim(strip_tags($keywords));

echo “<meta name=\”description\” content=\”$description\” />

<meta name=\”keywords\” content=\”$keywords\” />”;

}

elseif (is_tag())//TAG标签关键字和描述

{

$description = ‘xxxx’;

//5.29更新,防止描述为空时导致多个分类目录元描述重复,不利于SEO

if (!empty($description) && get_query_var(‘paged’)) {

$description .= ‘(第’.get_query_var(‘paged’).’页)’;

}

$keywords = single_tag_title(”, false);//这里调用TAG标签名称作为关键字(keywords)

$description = trim(strip_tags($description));

$keywords = trim(strip_tags($keywords));

echo “<meta name=\”description\” content=\”$description\” />

<meta name=\”keywords\” content=\”$keywords\” />”;

}

elseif (is_archive())//归档列表描述关键词设置

{

$description =’xxxxx’;

$keywords = “xxxxx”;

$description = trim(strip_tags($description));

$keywords = trim(strip_tags($keywords));

echo “<meta name=\”description\” content=\”$description\” />

<meta name=\”keywords\” content=\”$keywords\” />”;

}

?>

我的网站描述关键词2个部分是如此设置,一个网站的关键词描述是否设置或者设置的好坏都会影响搜索引擎的排名,一个没有设置描述的网站,搜索引擎会抓去一段描述(那就是看bd的给你的该页面的评价程度以及随机性了,好坏是他说了算)。所以站长做网站不要抱着无所谓的态度放弃对网站的前期的优化工作。

 

THE END