Created
November 16, 2017 23:39
-
-
Save deeman/3f77ab69d2ea096a9212d771b1b433ad to your computer and use it in GitHub Desktop.
(SEO) Create Meta Description From Content
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
This creates a custom SEO function for meta description. | |
The function automatically create (155 words) Meta Description From Content. | |
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
function create_meta_desc() { | |
global $post; | |
if (!is_single()) { return; } | |
$meta = strip_tags($post->post_content); | |
$meta = strip_shortcodes($meta); | |
$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta); | |
$meta = substr($meta, 0, 155); | |
echo "<meta name='description' content='$meta' />"; | |
} | |
add_action('wp_head', 'create_meta_desc'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment