WordPress标题标签用的最多的是wp_title函数,所以在此之前,一定要好好了解下该函数。,用法一,首页:博客名 – 博客描述,首页翻页:博客名 - 第 2 页,其他页:页面名 – 博客名,其他页翻页:页面名 – 博客名 - 第 2 页,如果希望首页翻页显示:博客名 – 博客描述 - 第 2 页,只需要去除if语句中的 && !is_paged(),另外,我摘录了官方默认主题twentyeleven的标题写法,功能跟SJY上面写的语句相似。,用法二,首页:博客名,其他页:跟用法一相同,只定制化首页标题,首页标题为 古代爱情故事_现代爱情故事_古今爱情故事网,其他页标题为 页面名称 – 博客名,最后就是分页大于2的,在后面加 第 N 页,不同页面用不同标签,每个页面最好有且仅有一个H1标签,在首页,logo部分一般就是H1标签,而内页,文章标题用H1标签,首页就只能用其他标签替代了。,这行代码的意思是,如果是首页那么logo部分用H1标签,如果是其他页面则用H4标签。,SEO专用,首页我这里直接写死了,如果是文章页,那么优先取自定义字段title_value中的值,该字段无值就直接调用文章标题;描述中有值则取值,无值则自动截取文章的前200个字符;关键字有值取值,无值取tag作为关键字。,其他页面,格式一律为:页面名 – 博客标题,最后,在需要调用描述与关键字的页面中插入以下代码,给自定义字段添加面板,为了更方便的撰写自定义标题,描述,关键字,给其增加一个面板,就像编辑页面的分类目录面板一样。具体原理参考文章 WordPress添加自定义字段面板,为了节省时间,下面直接给出代码,把代码复制到functions.php文件中,去后台看看吧,可以抛弃一些SEO插件了,原文地址 http://www.sjyhome.com/wordpress/wp-title.html,
WordPress标题标签用的最多的是wp_title函数,所以在此之前,一定要好好了解下该函数。
用法一
首页:博客名 – 博客描述
首页翻页:博客名 - 第 2 页
其他页:页面名 – 博客名
其他页翻页:页面名 – 博客名 - 第 2 页
如果希望首页翻页显示:博客名 – 博客描述 - 第 2 页
只需要去除if语句中的 && !is_paged()
另外,我摘录了官方默认主题twentyeleven的标题写法,功能跟SJY上面写的语句相似。
tag based on what is being viewed. */ global $page, $paged; wp_title( "-", true, "right" ); // Add the blog name. bloginfo( "name" ); // Add the blog description for the home/front page. $site_description = get_bloginfo( "description", "display" ); if ( $site_description && ( is_home() || is_front_page() ) ) echo " - $site_description"; // Add a page number if necessary: if ( $paged >= 2 || $page >= 2 ) echo " - " . sprintf( __( "Page %s", "twentyten" ), max( $paged, $page ) ); ?>
用法二
首页:博客名
其他页:跟用法一相同
只定制化首页标题
首页标题为 古代爱情故事_现代爱情故事_古今爱情故事网
其他页标题为 页面名称 – 博客名
最后就是分页大于2的,在后面加 第 N 页
不同页面用不同标签
每个页面最好有且仅有一个H1标签,在首页,logo部分一般就是H1标签,而内页,文章标题用H1标签,首页就只能用其他标签替代了。
< class="logo">/">>
这行代码的意思是,如果是首页那么logo部分用H1标签,如果是其他页面则用H4标签。
SEO专用
ID, "title_value", true); $title2 = get_the_title(); $title = $title1 ? $title1 : $title2; $title = $title." – ".get_bloginfo("name"); $description1 = get_post_meta($post->ID, "description_value", true); $description2 = mb_strimwidth(strip_tags($post->post_content), 0, 200, "…"); $description = $description1 ? $description1 : $description2; $keywords = get_post_meta($post->ID, "keywords_value", true); if($keywords == "") { $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $keywords = $keywords . $tag->name . ", "; } $keywords = rtrim($keywords, ", "); } }else{$title=wp_title(" - ",true,"right");bloginfo("name");} if($paged<2){echo $title;}else{echo "$title – 第 $paged 页";} $description=preg_replace(array("/\s/","/ /"),"",$description); $description=strip_tags($description); ?>
首页我这里直接写死了,如果是文章页,那么优先取自定义字段title_value中的值,该字段无值就直接调用文章标题;描述中有值则取值,无值则自动截取文章的前200个字符;关键字有值取值,无值取tag作为关键字。
其他页面,格式一律为:页面名 – 博客标题
最后,在需要调用描述与关键字的页面中插入以下代码
给自定义字段添加面板
为了更方便的撰写自定义标题,描述,关键字,给其增加一个面板,就像编辑页面的分类目录面板一样。具体原理参考文章 WordPress添加自定义字段面板
为了节省时间,下面直接给出代码,把代码复制到functions.php文件中
/*SEO选项*/
$new_meta_boxes =
array(
"title" => array(
"name" => "title",
"std" => "这里填自定义标题",
"title" => "TITLE:"),
"description" => array(
"name" => "description",
"std" => "这里填默认的网页描述",
"title" => "网页描述:"),
"keywords" => array(
"name" => "keywords",
"std" => "这里填默认的网页关键字",
"title" => "关键字:")
);
function new_meta_boxes() {
global $post, $new_meta_boxes;
foreach($new_meta_boxes as $meta_box) {
$meta_box_value = get_post_meta($post->ID, $meta_box["name"]."_value", true);
if($meta_box_value == "")
$meta_box_value = $meta_box["std"];
// 自定义字段标题
echo"".$meta_box["title"]."
";
// 自定义字段输入框
echo "
";
}
echo "";
}
function create_meta_box() {
global $theme_name;
if ( function_exists("add_meta_box") ) {
add_meta_box( "new-meta-boxes", "SEO选项", "new_meta_boxes", "post", "normal", "high" );
}
}
function save_postdata( $post_id ) {
global $new_meta_boxes;
if ( !wp_verify_nonce( $_POST["newmetaboxes_noncename"], plugin_basename(__FILE__) ))
return;
if ( !current_user_can( "edit_posts", $post_id ))
return;
foreach($new_meta_boxes as $meta_box) {
$data = $_POST[$meta_box["name"]."_value"];
if(get_post_meta($post_id, $meta_box["name"]."_value") == "")
add_post_meta($post_id, $meta_box["name"]."_value", $data, true);
elseif($data != get_post_meta($post_id, $meta_box["name"]."_value", true))
update_post_meta($post_id, $meta_box["name"]."_value", $data);
elseif($data == "")
delete_post_meta($post_id, $meta_box["name"]."_value", get_post_meta($post_id, $meta_box["name"]."_value", true));
}
}
add_action("admin_menu", "create_meta_box");
add_action("save_post", "save_postdata");
去后台看看吧,可以抛弃一些SEO插件了
原文地址 http://www.sjyhome.com/wordpress/wp-title.html
,
WordPress标题标签用的最多的是wp_title函数,所以在此之前,一定要好好了解下该函数。
用法一
首页:博客名 – 博客描述
首页翻页:博客名 - 第 2 页
其他页:页面名 – 博客名
其他页翻页:页面名 – 博客名 - 第 2 页
如果希望首页翻页显示:博客名 – 博客描述 - 第 2 页
只需要去除if语句中的 && !is_paged()
另外,我摘录了官方默认主题twentyeleven的标题写法,功能跟SJY上面写的语句相似。
tag based on what is being viewed. */ global $page, $paged; wp_title( "-", true, "right" ); // Add the blog name. bloginfo( "name" ); // Add the blog description for the home/front page. $site_description = get_bloginfo( "description", "display" ); if ( $site_description && ( is_home() || is_front_page() ) ) echo " - $site_description"; // Add a page number if necessary: if ( $paged >= 2 || $page >= 2 ) echo " - " . sprintf( __( "Page %s", "twentyten" ), max( $paged, $page ) ); ?>
用法二
首页:博客名
其他页:跟用法一相同
只定制化首页标题
首页标题为 古代爱情故事_现代爱情故事_古今爱情故事网
其他页标题为 页面名称 – 博客名
最后就是分页大于2的,在后面加 第 N 页
不同页面用不同标签
每个页面最好有且仅有一个H1标签,在首页,logo部分一般就是H1标签,而内页,文章标题用H1标签,首页就只能用其他标签替代了。
< class="logo">/">>
这行代码的意思是,如果是首页那么logo部分用H1标签,如果是其他页面则用H4标签。
SEO专用
ID, "title_value", true); $title2 = get_the_title(); $title = $title1 ? $title1 : $title2; $title = $title." – ".get_bloginfo("name"); $description1 = get_post_meta($post->ID, "description_value", true); $description2 = mb_strimwidth(strip_tags($post->post_content), 0, 200, "…"); $description = $description1 ? $description1 : $description2; $keywords = get_post_meta($post->ID, "keywords_value", true); if($keywords == "") { $tags = wp_get_post_tags($post->ID); foreach ($tags as $tag ) { $keywords = $keywords . $tag->name . ", "; } $keywords = rtrim($keywords, ", "); } }else{$title=wp_title(" - ",true,"right");bloginfo("name");} if($paged<2){echo $title;}else{echo "$title – 第 $paged 页";} $description=preg_replace(array("/\s/","/ /"),"",$description); $description=strip_tags($description); ?>
首页我这里直接写死了,如果是文章页,那么优先取自定义字段title_value中的值,该字段无值就直接调用文章标题;描述中有值则取值,无值则自动截取文章的前200个字符;关键字有值取值,无值取tag作为关键字。
其他页面,格式一律为:页面名 – 博客标题
最后,在需要调用描述与关键字的页面中插入以下代码
给自定义字段添加面板
为了更方便的撰写自定义标题,描述,关键字,给其增加一个面板,就像编辑页面的分类目录面板一样。具体原理参考文章 WordPress添加自定义字段面板
为了节省时间,下面直接给出代码,把代码复制到functions.php文件中
/*SEO选项*/
$new_meta_boxes =
array(
"title" => array(
"name" => "title",
"std" => "这里填自定义标题",
"title" => "TITLE:"),
"description" => array(
"name" => "description",
"std" => "这里填默认的网页描述",
"title" => "网页描述:"),
"keywords" => array(
"name" => "keywords",
"std" => "这里填默认的网页关键字",
"title" => "关键字:")
);
function new_meta_boxes() {
global $post, $new_meta_boxes;
foreach($new_meta_boxes as $meta_box) {
$meta_box_value = get_post_meta($post->ID, $meta_box["name"]."_value", true);
if($meta_box_value == "")
$meta_box_value = $meta_box["std"];
// 自定义字段标题
echo"".$meta_box["title"]."
";
// 自定义字段输入框
echo "
";
}
echo "";
}
function create_meta_box() {
global $theme_name;
if ( function_exists("add_meta_box") ) {
add_meta_box( "new-meta-boxes", "SEO选项", "new_meta_boxes", "post", "normal", "high" );
}
}
function save_postdata( $post_id ) {
global $new_meta_boxes;
if ( !wp_verify_nonce( $_POST["newmetaboxes_noncename"], plugin_basename(__FILE__) ))
return;
if ( !current_user_can( "edit_posts", $post_id ))
return;
foreach($new_meta_boxes as $meta_box) {
$data = $_POST[$meta_box["name"]."_value"];
if(get_post_meta($post_id, $meta_box["name"]."_value") == "")
add_post_meta($post_id, $meta_box["name"]."_value", $data, true);
elseif($data != get_post_meta($post_id, $meta_box["name"]."_value", true))
update_post_meta($post_id, $meta_box["name"]."_value", $data);
elseif($data == "")
delete_post_meta($post_id, $meta_box["name"]."_value", get_post_meta($post_id, $meta_box["name"]."_value", true));
}
}
add_action("admin_menu", "create_meta_box");
add_action("save_post", "save_postdata");
去后台看看吧,可以抛弃一些SEO插件了
原文地址 http://www.sjyhome.com/wordpress/wp-title.html
此处评论已关闭