Code to achieve WordPress automatic keywords keywords and description

The following code to achieve the label as a keyword; to summary for the description, if not fill out the abstract, then automatically intercept the article before the 200 words for the description. (Tutorial transferred from: DeveWork)

Code to achieve WordPress automatic keywords and description:
The following code put under your theme funtions.php the last one?

// Automatic keywords and description
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_excerpt) {// If the article abstract exists on the article summary to describe
$ 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 article before the 200 words for 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 the article tag as a keyword
$ keywords = implode (‘,’, array_unique ((array) $ keywordarray));
} else {// if it is not an article page
$press = ‘wordpress, wordpress theme, wordpress tutorial, wordpress theme download, wordpress blog theme, wordpress corporate theme, wordpress theme custom’; // quotation marks between your blog keywords,
$ description = ‘theme cat, dedicated to the majority of users to provide the latest and most complete wordpress theme’; / / quotation marks between your blog to write a simple description, do not over 200 words
}
// Output keywords
$ output. = ‘<meta name = “keywords” content = “‘. $ keywords. ‘” />’.
$ output. = ‘<meta name = “description” content = “‘. $ description. ‘” />’.
// output description
echo “$ outputn”;
}
add_action (‘wp_head’, ‘meta_SEO’); // add the meta_SEO function to the header

The contents of lines 43 and 44 need to be modified according to your website.