Add post SEO code for WordPress blog posts
preface
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);
use
Postscript