Skip to content

Instantly share code, notes, and snippets.

@PascaleBeier
Last active March 12, 2017 17:28
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 PascaleBeier/4ea657796d34de2d9c763985fbd29959 to your computer and use it in GitHub Desktop.
Save PascaleBeier/4ea657796d34de2d9c763985fbd29959 to your computer and use it in GitHub Desktop.
meta-description-spengler
function add_custom_meta_description() {
global $post;
$current_post = $post->ID;
$excerpt = get_the_excerpt( $current_post );
$cf_description = get_post_meta( $current_post, "description", true );
$output = 0;
if ( ! empty( $cf_description ) ) {
$output = $cf_description;
} elseif ( ! empty( $excerpt ) ) {
$output = $excerpt;
}
if ( ! empty( $output ) ) { ?>
<meta name="description" content="<?php echo $output ?>">
<?php }
}
add_action( 'wp_head', 'add_custom_meta_description', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment