Skip to content

Instantly share code, notes, and snippets.

@wbxpress
Created June 23, 2021 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbxpress/bb3074b3d997a797f3a028bb5ac7daf2 to your computer and use it in GitHub Desktop.
Save wbxpress/bb3074b3d997a797f3a028bb5ac7daf2 to your computer and use it in GitHub Desktop.
/** Add meta for SEO **/
function wbxpress_add_meta_tags() {
// homepage
if (is_home()) {
echo '<meta name="description" content="' . get_bloginfo( "description" ) . '" />' . "\n";
}
// single post page
if ( is_singular() ) {
global $post;
$meta_description = strip_tags($post->post_excerpt);
echo '<meta name="description" content="' . $meta_description . '" />' . "\n";
}
// category page
if ( is_category() ) {
$meta_description = strip_tags(category_description());
echo '<meta name="description" content="' . $meta_description . '" />' . "\n";
}
// tags page
if ( is_tag() ) {
$meta_description = strip_tags(tag_description());
echo '<meta name="description" content="' . $meta_description . '" />' . "\n";
}
}
add_action( 'wp_head', 'wbxpress_add_meta_tags');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment