Create excerpt for meta description
-
This code, residing in the head section of the “single” template page, creates an excerpt for the meta description (which is often the text that appears in search results).
<?php $post = $wp_query->post; $descrip = strip_tags($post->post_content); $descrip_more = ''; if (strlen($descrip) > 155) { $descrip = substr($descrip,0,155); $descrip_more = ' ...'; } $descrip = str_replace('"', '', $descrip); $descrip = str_replace("'", '', $descrip); $descripwords = preg_split('/[\n\r\t ]+/', $descrip, -1, PREG_SPLIT_NO_EMPTY); array_pop($descripwords); $descrip = implode(' ', $descripwords) . $descrip_more; echo '<meta name="description" content="'.$descrip.'">'; ?>
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
- The topic ‘Create excerpt for meta description’ is closed to new replies.