打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
4 Tips about how to optimize wordpress for seo | Sven's Blog

Today Sven will introduce some tips about wordpress Seo,SEO means Search Engine Optimization.If you wanna your wordpress site more attractive to search engine,first you would know search engine’s taste.There are lots of plugins which have the same function,but if you want to do it by yourself,follow Sven and do the following job:

SEO for header

First is Seo for header,add following code to header.php

Attention:if there are already title/description/keywords in header.php,first delete the old one.Never forget use your own information instead of the following one.^ ^

it can add tags als the keywords of the single page,it will help a lot.

<?phpif(is_home()) { ?><title>Sven's Blog,Sven的博客</title><meta content="Welcome to Sven's Blog!欢迎来到Sven的博客" name="Description"/><meta content="Sven,Sven Qin,Wordpress,Sven's Blog,sven的博客" name="Keywords"/><?php } ?><?phpif(is_category()) { ?><title><?php echo trim(wp_title('',0)); ?> | <?php bloginfo(name);?><? $paged = get_query_var('paged'); if ( $paged > 1 ) printf('page %s ',$paged); ?></title><meta content="<?php echo trim(strip_tags(category_description())); ?>" name="Description"/><meta content="<?php echo single_cat_title(); ?>" name="Keywords"/><?php } ?><?phpif(is_single())  { ?><title><?php echo trim(wp_title('',0)); ?> | <?php bloginfo(name);?><? $paged = get_query_var('paged'); if ( $paged > 1 ) printf('page %s ',$paged); ?></title><meta name="description" content="<?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 200,"......","utf-8"); ?>" /><?php$keywords = get_the_tags();$keyword = '';foreach ($keywords as $value) {$keyword .= $value->name.',';}?><meta name="keywords" content="<?php echo $keyword ;?>" /><?php }?><?phpif(is_tag()) { ?><title><?php echo trim(wp_title('',0)); ?>_tag page<? $paged = get_query_var('paged'); if ( $paged > 1 ) printf('page %s ',$paged); ?></title><meta name="description" content="<?php echo trim(strip_tags(tag_description())); ?><? $paged = get_query_var('paged'); if ( $paged > 1 ) printf('page %s ',$paged); ?>" /><meta name="keywords" content="<?php echo trim(wp_title('',0)); ?>" /><?php }?>

Second code for header.php,it can use the first 100 byte as the description of the page.

<?phpif(is_single())  { ?><meta name="description" content="<?php echo trim(wp_title('',0)); ?>-<?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 100,"......","utf-8"); ?>" /><?php }?>

add “nofollow” tag to external links automaticly

following code can add rel=”nofollow” to external links,just copy the code to functions.php:

add_filter( 'the_content', 'sven_seo_wl');function sven_seo_wl( $content ) {    $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";    if(preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {        if( !empty($matches) ) {             $srcUrl = get_option('siteurl');            for ($i=0; $i < count($matches); $i++)            {                     $tag = $matches[$i][0];                $tag2 = $matches[$i][0];                $url = $matches[$i][0];                $noFollow = '';                $pattern = '/target\s*=\s*"\s*_blank\s*"/';                preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);                if( count($match) < 1 )                    $noFollow .= ' target="_blank" ';                     $pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/';                preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);                if( count($match) < 1 )                    $noFollow .= ' rel="nofollow" ';                 $pos = strpos($url,$srcUrl);                if ($pos === false) {                    $tag = rtrim ($tag,'>');                    $tag .= $noFollow.'>';                    $content = str_replace($tag2,$tag,$content);                }            }        }    }      $content = str_replace(']]>', ']]>', $content);    return $content;}

Add alt to images

the same,adding the code to functions.php:

add_filter('the_content', 'svenseo');function svenseo($content) {       global $post;       $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";       $replacement = '<a$1href=$2$3.$4$5 alt="'.$post->post_title.'" title="'.$post->post_title.'"$6>';       $content = preg_replace($pattern, $replacement, $content);       return $content;}

That’s all.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
15个实用的PHP正则表达式
15个超实用的php正则表达式
wordpress文章自动添加标签链接 | wordpress教程网
自动添加内部链接的Wordpress插件
WordPress标签Tag、评论及阅读全文添加nofollow详解
WordPress header 自动添加关键词和描述
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服