麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > CMS > Wordpress > 正文

不用插件就能解決wordpress的SEO,修改functions.php加入如下代碼

2024-09-07 00:51:25
字體:
供稿:網(wǎng)友

不用插件就能解決wordpress的SEO,修改functions.php加入如下代碼即可.

很多人使用插件對wordpress進(jìn)行SEO優(yōu)化,其實(shí)很多是沒有必要用到的,這里為大家提供了一個(gè)通用的wordpress 頁面SEO設(shè)置方法.

將以下代碼放置于你主題的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.     // 描述 
  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 (!emptyempty($seo_desc)) { 
  12.             $content = $seo_desc
  13.         } else if (!emptyempty($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.     // 關(guān)鍵字 
  26.     $keys = get_post_meta($post->ID, 'mm_seo_keywords', true); 
  27.     $cats = get_the_category(); 
  28.     $tags = get_the_tags(); 
  29.     if (emptyempty($keys)) { 
  30.         if (!emptyempty($cats)) foreach($cats as $cat$keys .= $cat->name . ', '
  31.         if (!emptyempty($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設(shè)置 
  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.     // 標(biāo)題 
  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 (!emptyempty($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;//開源軟件:Vevb.com 
  70.     else                              $seo_title = $name . ' | ' . $description
  71.  
  72.     $output .= "/t/t" . '<title>' . esc_attr($seo_title . $page_number) . '</title>' . "/n"
  73.  
  74.     return $output

以上方法包含了標(biāo)題、關(guān)鍵字、描述、robots設(shè)置,你在需要使用的頁面添加以上函數(shù).

以上函數(shù)可以在:主頁、文章頁、標(biāo)簽頁、分類頁、歸檔頁、搜索頁、404頁面使用,如果你需要其他頁面,可以修改以上代碼實(shí)現(xiàn).

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产91中文字幕 | 国产精品一区在线观看 | 日本黄色a视频 | 黄色成人av在线 | 国产精品久久久久一区二区 | 狠狠干夜夜草 | 色人阁在线视频 | 毛片视频大全 | 日日鲁夜夜视频热线播放 | 正在播放91视频 | 深夜影院一级毛片 | 成年人视频免费 | 久久伊人精品视频 | 欧美日韩在线免费观看 | 极品销魂一区二区三区 | 欧美日本另类 | 噜噜在线视频 | 99这里精品 | 毛片免费视频在线观看 | 丰满年轻岳中文字幕一区二区 | 美女久久久久 | 成人午夜在线免费视频 | 国产精品爱久久久久久久 | 成年性羞羞视频免费观看无限 | 日本免费一区二区三区四区 | 天天色宗合| 国产在线精品一区二区夜色 | 高清做爰免费无遮网站挡 | 羞羞视频免费网站男男 | 亚洲第一页综合 | 有色视频在线观看 | 国产精品jk白丝蜜臀av软件 | 欧美成人小视频 | 国产一区二区在线免费播放 | 成年免费视频黄网站在线观看 | 国产成人午夜精品 | 色婷婷久久一区二区 | 亚洲精品久久久久www | 欧美成人一区二区三区电影 | 精品久久久久久久久久久久久 | 牛牛热这里只有精品 |