最近认识了几个做英文站seo的朋友,也是用wp的,但是seo的效果不是很好,毕竟现在seo的插件很容易被搜索引擎识别,再说seo的设置就那几项,如果用seo插件岂不是浪费?能用代码就用代码就ok了!中文站不要使用了,效果不好!
先说代码,将下面代码加入到function.php中
- function basic_wp_seo() {
- global $page, $paged, $post;
- $default_keywords = 'wordpress, plugins, themes, design, dev, development, security, htaccess, apache, php, sql, html, css, jquery, javascript, tutorials'; // customize
- $output = '';
- // description
- $seo_desc = get_post_meta($post->ID, 'mm_seo_desc', true);
- $description = get_bloginfo('description', 'display');
- $pagedata = get_post($post->ID);
- if (is_singular()) {
- if (!emptyempty($seo_desc)) {
- $content = $seo_desc;
- } else if (!emptyempty($pagedata)) {
- $content = apply_filters('the_excerpt_rss', $pagedata->post_content);
- $content = substr(trim(strip_tags($content)), 0, 155);
- $content = preg_replace('#n#', ' ', $content);
- $content = preg_replace('#s{2,}#', ' ', $content);
- $content = trim($content);
- }
- } else {
- $content = $description;
- }
- $output .= '<meta name="description" content="' . esc_attr($content) . '">' . "n";
- // keywords
- $keys = get_post_meta($post->ID, 'mm_seo_keywords', true);
- $cats = get_the_category();
- $tags = get_the_tags();
- if (emptyempty($keys)) {
- if (!emptyempty($cats)) foreach($cats as $cat) $keys .= $cat->name . ', ';
- if (!emptyempty($tags)) foreach($tags as $tag) $keys .= $tag->name . ', ';
- $keys .= $default_keywords;
- }
- $output .= "tt" . '<meta name="keywords" content="' . esc_attr($keys) . '">' . "n";
- // robots
- if (is_category() || is_tag()) {
- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
- if ($paged > 1) {
- $output .= "tt" . '<meta name="robots" content="noindex,follow">' . "n";
- } else {
- $output .= "tt" . '<meta name="robots" content="index,follow">' . "n";
- }
- } else if (is_home() || is_singular()) {
- $output .= "tt" . '<meta name="robots" content="index,follow">' . "n";
- } else {
- $output .= "tt" . '<meta name="robots" content="noindex,follow">' . "n";
- }
- // title
- $title_custom = get_post_meta($post->ID, 'mm_seo_title', true);
- $url = ltrim(esc_url($_SERVER['REQUEST_URI']), '/');
- $name = get_bloginfo('name', 'display');
- $title = trim(wp_title('', false));
- $cat = single_cat_title('', false);
- $tag = single_tag_title('', false);
- $search = get_search_query();
- if (!emptyempty($title_custom)) $title = $title_custom;
- if ($paged >= 2 || $page >= 2) $page_number = ' | ' . sprintf('Page %s', max($paged, $page));
- else $page_number = '';
- if (is_home() || is_front_page()) $seo_title = $name . ' | ' . $description;
- elseif (is_singular()) $seo_title = $title . ' | ' . $name;
- elseif (is_tag()) $seo_title = 'Tag Archive: ' . $tag . ' | ' . $name;
- elseif (is_category()) $seo_title = 'Category Archive: ' . $cat . ' | ' . $name;
- elseif (is_archive()) $seo_title = 'Archive: ' . $title . ' | ' . $name;
- elseif (is_search()) $seo_title = 'Search: ' . $search . ' | ' . $name;
- elseif (is_404()) $seo_title = '404 - Not Found: ' . $url . ' | ' . $name;
- else $seo_title = $name . ' | ' . $description;
- $output .= "tt" . '<title>' . esc_attr($seo_title . $page_number) . '</title>' . "n";
- return $output;
- }
手动把上面的关键词修改为自己的关键词,然后进行调用
在head中将<title></title>修改为
- <?php echo basic_wp_seo(); ?>
即可
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)