Excellent software and practical tutorials
You only need a piece of code to easily add TAG tags automatically, which is a very beneficial function in SEO optimization. I won’t introduce too much about the role of tag tags in WordPress articles. TAG tags can be used to find relevant content quickly and easily. Today, I will share a piece of code that automatically adds tag tags to articles. You can easily add tags automatically by copying and pasting it.
/* Automatically add tags to articles */
add_action('save_post', 'auto_add_tags');
function auto_add_tags(){
$tags = get_tags( array('hide_empty' => false) );
$post_id = get_the_ID();
$post_content = get_post($post_id)->post_content;
if ($tags) {
foreach ( $tags as $tag ) {
// If the article content has used tags, automatically add these tags
if (strpos($post_content, $tag->name) !== false)
wp_set_post_tags( $post_id, $tag->name, true );
}
}
}
Copy the above code into Appearance -> Theme Editor ->functionsJust copy it to the functions.php file in the folder! If you don’t know PHP, just copy it before the “?>” at the end of the functions.php file.
After confirming and saving, the code will take effect. The next time you add an article, you don’t have to manually enter the TAG tag, the system will add it automatically.