中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

非插件實現(xiàn)高效的SEO優(yōu)化

2019-03-25    來源:知更鳥

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

WordPress有很多SEO插件來幫助進行搜索引擎優(yōu)化。如果你不想使用插件,下面這個高效的代碼,將使你的博客對搜索引擎更加友好。

將下面代碼粘貼到你的functions.php文件:

  1. function basic_wp_seo() {  
  2.     global $page$paged$post;  
  3.     $default_keywords = 'wordpress, plugins, themes, design, dev, development, security, htaccess, apache, php, sql, html, css, jquery, javascript, tutorials'; // customize  
  4.     $output = '';  
  5.   
  6.     // description  
  7.     $seo_desc = get_post_meta($post->ID, 'mm_seo_desc', true);  
  8.     $description = get_bloginfo('description', 'display');  
  9.     $pagedata = get_post($post->ID);  
  10.     if (is_singular()) {  
  11.         if (!empty($seo_desc)) {  
  12.             $content = $seo_desc;  
  13.         } else if (!empty($pagedata)) {  
  14.             $content = apply_filters('the_excerpt_rss', $pagedata->post_content);  
  15.             $content = substr(trim(strip_tags($content)), 0, 155);  
  16.             $content = preg_replace('#\n#', ' ', $content);  
  17.             $content = preg_replace('#\s{2,}#', ' ', $content);  
  18.             $content = trim($content);  
  19.         }   
  20.     } else {  
  21.         $content = $description;      
  22.     }  
  23.     $output .= '<meta name="description" content="' . esc_attr($content) . '">' . "\n";  
  24.   
  25.     // keywords  
  26.     $keys = get_post_meta($post->ID, 'mm_seo_keywords', true);  
  27.     $cats = get_the_category();  
  28.     $tags = get_the_tags();  
  29.     if (empty($keys)) {  
  30.         if (!empty($cats)) foreach($cats as $cat$keys .= $cat->name . ', ';  
  31.         if (!empty($tags)) foreach($tags as $tag$keys .= $tag->name . ', ';  
  32.         $keys .= $default_keywords;  
  33.     }  
  34.     $output .= "\t\t" . '<meta name="keywords" content="' . esc_attr($keys) . '">' . "\n";  
  35.   
  36.     // robots  
  37.     if (is_category() || is_tag()) {  
  38.         $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;  
  39.         if ($paged > 1) {  
  40.             $output .=  "\t\t" . '<meta name="robots" content="noindex,follow">' . "\n";  
  41.         } else {  
  42.             $output .=  "\t\t" . '<meta name="robots" content="index,follow">' . "\n";  
  43.         }  
  44.     } else if (is_home() || is_singular()) {  
  45.         $output .=  "\t\t" . '<meta name="robots" content="index,follow">' . "\n";  
  46.     } else {  
  47.         $output .= "\t\t" . '<meta name="robots" content="noindex,follow">' . "\n";  
  48.     }  
  49.   
  50.     // title  
  51.     $title_custom = get_post_meta($post->ID, 'mm_seo_title', true);  
  52.     $url = ltrim(esc_url($_SERVER['REQUEST_URI']), '/');  
  53.     $name = get_bloginfo('name', 'display');  
  54.     $title = trim(wp_title('', false));  
  55.     $cat = single_cat_title('', false);  
  56.     $tag = single_tag_title('', false);  
  57.     $search = get_search_query();  
  58.   
  59.     if (!empty($title_custom)) $title = $title_custom;  
  60.     if ($paged >= 2 || $page >= 2) $page_number = ' | ' . sprintf('Page %s', max($paged$page));  
  61.     else $page_number = '';  
  62.   
  63.     if (is_home() || is_front_page()) $seo_title = $name . ' | ' . $description;  
  64.     elseif (is_singular())            $seo_title = $title . ' | ' . $name;  
  65.     elseif (is_tag())                 $seo_title = 'Tag Archive: ' . $tag . ' | ' . $name;  
  66.     elseif (is_category())            $seo_title = 'Category Archive: ' . $cat . ' | ' . $name;  
  67.     elseif (is_archive())             $seo_title = 'Archive: ' . $title . ' | ' . $name;  
  68.     elseif (is_search())              $seo_title = 'Search: ' . $search . ' | ' . $name;  
  69.     elseif (is_404())                 $seo_title = '404 - Not Found: ' . $url . ' | ' . $name;  
  70.     else                              $seo_title = $name . ' | ' . $description;  
  71.   
  72.     $output .= "\t\t" . '<title>' . esc_attr($seo_title . $page_number) . '</title>' . "\n";  
  73.   
  74.     return $output;  
  75. }  

需修改一下$default_keywords 后面默認的關鍵字

使用方法:用下面代碼:

  1. <?php echo basic_wp_seo(); ?>  

替換主題header.php模板

  1. <title></title>  

注:可能不同的主題有所區(qū)別。

文章來源:http://zmingcx.com/non-plug-in-for-efficient-seo-optimization.html

標簽: Wordpress 搜索引擎優(yōu)化 SEO 

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:網(wǎng)站優(yōu)化策略

下一篇:域名中包含關鍵字和網(wǎng)站排名有關系嗎?