No plug-in, code implements WordPress article SEO

» WordPress » No plug-in, code implements WordPress article SEO

Add post SEO code for WordPress blog posts

无插件,代码实现WordPress文章SEO-极客公园

preface

The search engine will not only browse the home page of our website, but also browse the article page. It will automatically add some keywords to the article page. The article description may increase the SEO affinity, increase the opportunity to include articles. It is good to use simple code, without the need for plug-ins to bother.

code

 //SEO //Automatic keywords and descriptions function get_cats_name() { $allcats=get_categories(); foreach ($allcats as $category)  { $keywords[] = $category->cat_name; } return $keywords; } // utf8 substr function utf8Substr($str, $from, $len) { return preg_replace('#^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$from.'}'. '((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,'.$len.'}).*#s', '$1',$str); } // Meta SEO function meta_SEO() { global $post; $output = ''; If (is_single()) {//If it is an article page $keywords = '';  $description = ''; If ($post ->post_excerp) {//If the article summary exists, it will be described as the article summary $description = $post->post_excerpt; $description = str_replace("rn","",$description); $description = str_replace("n","",$description); $description = str_replace(""","'",$description); $description .= '...'; }Else {//If the article summary does not exist, truncate the first 200 words of the article as the description $description = utf8Substr(strip_tags($post->post_content),0,200); $description = str_replace("rn","",$description); $description = str_replace("n","",$description); $description = str_replace(""","'",$description); $description .= '...'; }  $tags = wp_get_post_tags($post->ID);// Take the article tag foreach ($tags as $tag ) { $keywordarray[] = $tag->name; } //Use article tags as keywords $keywords = implode(',',array_unique((array)$keywordarray)); }Else {//If it is not the article page $keywords='Fun Park, Post Bar Dynamics, wordpress, system operation, network applications, software, IT information, Post Bar, Firefox'// Write keywords of your blog between quotation marks, disconnect $description='Follow the post bar dynamics and toss Firefox'// Write a simple description of your blog between quotation marks, no more than 200 words } //Output Keyword $output .= '< meta name="keywords" content="' . $ keywords . '" />' .  "n"; $output .= '< meta name="description" content="' . $ description . '" />' .  "n"; //Output Description echo "$outputn"; } add_action('wp_head', 'meta_SEO');// Add meta_SEO function to header information add_filter( 'comment_text' , 'ludou_comment_add_at', 20, 2);
The author of this code found on the network is unknown, but I just share it

use

Insert this code into the topic function file functions.php.

Postscript

After all, using plug-ins will reduce the performance of the website to some extent. Therefore, unless necessary, code directly.

--End--

Post reply

Your email address will not be disclosed. Required items have been used * tagging

6 Replies to "No plug-in, code implements WordPress article SEO"