很多人使用插件对wordpress进行SEO优化,其实很多是没有必要用到的,wordpress教程网为大家提供了一个通用的wordpress页面SEO设置方法。
将以下代码放置于你主题的functions.php文件中
functionbasic_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=''; //描述 $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(!empty($seo_desc)){ $content=$seo_desc; }elseif(!empty($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.=''."n"; //关键字 $keys=get_post_meta($post->ID,'mm_seo_keywords',true); $cats=get_the_category(); $tags=get_the_tags(); if(empty($keys)){ if(!empty($cats))foreach($catsas$cat)$keys.=$cat->name.','; if(!empty($tags))foreach($tagsas$tag)$keys.=$tag->name.','; $keys.=$default_keywords; } $output.="tt".''."n"; //robots设置 if(is_category()||is_tag()){ $paged=(get_query_var('paged'))?get_query_var('paged'):1; if($paged>1){ $output.="tt".''."n"; }else{ $output.="tt".''."n"; } }elseif(is_home()||is_singular()){ $output.="tt".''."n"; }else{ $output.="tt".''."n"; } //标题 $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(!empty($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='TagArchive:'.$tag.'|'.$name; elseif(is_category())$seo_title='CategoryArchive:'.$cat.'|'.$name; elseif(is_archive())$seo_title='Archive:'.$title.'|'.$name; elseif(is_search())$seo_title='Search:'.$search.'|'.$name; elseif(is_404())$seo_title='404-NotFound:'.$url.'|'.$name; else$seo_title=$name.'|'.$description; $output.="tt".''.esc_attr($seo_title.$page_number).''."n"; return$output; }
上述就是wordpress技巧:页面SEO设置(标题,关键字,描述)分享!的全部内容,如果对大家有所用处且需要了解更多关于wordpresscms模板学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/wordpresscmst/912933.html