Skip to content

Instantly share code, notes, and snippets.

@chuckreynolds
Last active August 29, 2015 14:20
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 chuckreynolds/6478b4d2ad8b61ca560f to your computer and use it in GitHub Desktop.
Save chuckreynolds/6478b4d2ad8b61ca560f to your computer and use it in GitHub Desktop.
Get WPSEO title and description for category, taxonomy archives, pages, posts
<?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