Last active
March 12, 2017 17:28
-
-
Save PascaleBeier/4ea657796d34de2d9c763985fbd29959 to your computer and use it in GitHub Desktop.
meta-description-spengler
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 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