Last active
August 29, 2015 14:20
-
-
Save chuckreynolds/6478b4d2ad8b61ca560f to your computer and use it in GitHub Desktop.
Get WPSEO title and description for category, taxonomy archives, pages, posts
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 | |
// access wpseo_frontend class and get the seo title and seo description for output on archive pages | |
if ( class_exists( 'WPSEO_Frontend' ) ) { | |
$wpseo_object = WPSEO_Frontend::get_instance(); | |
$headline = $wpseo_object->title( false ); | |
$intro_text = $wpseo_object->metadesc( false ); | |
} | |
$headline = sanitize_text_field( $headline ); | |
$intro_text = sanitize_text_field( $intro_text ); | |
// these should work if not archives | |
# $headline = get_post_meta( $post->ID, '_yoast_wpseo_title', true ); | |
# $intro_text = get_post_meta( $post->ID, '_yoast_wpseo_metadesc', true ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment