Genesis SEO – Hope this Helps
-
I hope this helps someone if they are using the Genesis framework and its SEO settings. This can be added into your themes functions.php file. In this case, the function can easily be extended to cover categories and their pagination and tag archives if they have pagination. In the example below, I only need pagination on the main blog posts page. I was not able to get hold of the meta data for the static home page so a test is hardcoded in on the current url.
An issue for genesis framework users is that their homepage is often widgetized and doesn’t have a featured image. This means that in order to have a good AMP version with a featured image it is best to set up another page and have it pointedat the home amp page (there are admin settings to do that). It is why a test for the current url is needed in my case.
I am sure the plugin developers could make a better and more job of it and add it to the core.
/**
* Getting Genesis SEO meta into AMP pages
*/add_action( ‘amp_post_template_head’, ‘amp_post_template_metadata’,2);
function amp_post_template_metadata() {global $wp;
$current_url = home_url(add_query_arg(array(),$wp->request));// tag pages
if(is_tag()){
remove_action( ‘amp_post_template_head’, ‘amp_post_template_add_title’ );
remove_action(‘amp_post_template_head’,’ampforwp_meta_description’);echo ‘<title>’;
echo genesis_default_title();
echo ‘</title>’;
$description = genesis_get_seo_meta_description();
echo ‘<meta name=”description” content=”‘ . esc_attr( $description ) . ‘” />’ . “\n”;// we removed the amp title used by features.php above so need to set it – in this case not to display the word tag: . Basically setting in admin translation panel for tag archives will not show.
add_filter( ‘get_the_archive_title’, function ($title) {
$title = single_tag_title( ”, false );
return $title;
});
}// static home page
elseif($current_url==’https://www.mydomain.com/amp’){
remove_action(‘amp_post_template_head’,’ampforwp_meta_description’);
remove_action(‘amp_post_template_head’,’ampforwp_frontpage_title_markup’);
remove_action( ‘amp_post_template_head’, ‘amp_post_template_add_title’ );echo ‘<title>’;
echo ‘my super website’;
echo ‘</title>’;
$description = ‘not much to see here in my metadescription.’;
echo ‘<meta name=”description” content=”‘ . esc_attr( $description ) . ‘” />’ . “\n”;
}// blog posts page – yes is_home confuses but it is actually the posts page
elseif(is_home()){
remove_action(‘amp_post_template_head’,’ampforwp_frontpage_title_markup’);
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
echo ‘<title>’;// deal with pagination
if($paged > 1){
echo genesis_default_title() . ‘ – ‘ . $paged;
$description = genesis_get_seo_meta_description();
echo ‘<meta name=”description” content=”‘ . esc_attr( $description ) . ‘ – ‘ . $paged . ‘” />’ . “\n”;}else{
echo genesis_default_title();
$description = genesis_get_seo_meta_description();
echo ‘<meta name=”description” content=”‘ . esc_attr( $description ) . ‘” />’ . “\n”;
}
echo ‘</title>’;
}// posts and pages
else{
remove_action( ‘amp_post_template_head’, ‘amp_post_template_add_title’ );
remove_action(‘amp_post_template_head’,’ampforwp_meta_description’);
remove_action(‘amp_post_template_head’,’ampforwp_frontpage_title_markup’);echo ‘<title>’;
echo genesis_default_title();
echo ‘</title>’;
$description = genesis_get_seo_meta_description();
echo ‘<meta name=”description” content=”‘ . esc_attr( $description ) . ‘” />’ . “\n”;
}
}
- The topic ‘Genesis SEO – Hope this Helps’ is closed to new replies.