Created
August 31, 2022 19:19
-
-
Save asllanmaciel/fa7235c7cd71fdb05a41d1204fde2558 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wp24h_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_content); | |
$meta_description = strip_shortcodes($post->post_content); | |
$meta_description = str_replace(array("\n", "\r", "\t"), ' ', $meta_description); | |
$meta_description = substr($meta_description, 0, 160); | |
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"; | |
} | |
} | |
add_action( 'wp_head', 'wp24h_add_meta_tags'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment