Community Forums › Forums › Archived Forums › General Discussion › Default meta description to home description if emtpy
- This topic has 3 replies, 2 voices, and was last updated 9 years, 1 month ago by Leif.
-
AuthorPosts
-
February 16, 2015 at 2:46 pm #141044WhiteleyDesignsMember
Out of curiosity - what are other developers doing with regards to the meta description output on pages and posts? I know you can manually add the meta description using the on-page SEO options for any pages, posts, etc...but when that is left blank I've had to create a function to fallback to the home meta description just to the page has a description as it shouldn't be neglected.
The situation I've run into is when I am asked to work on larger sites and covert them into a Genesis Framework site I don't want to spend the time going through every single page and customizing the meta description. I do it for all the important pages, but I don't believe it is necessary for all pages. I've used the following as a fallback - it is the same genesis_seo_meta_description except that I added a check to see if it is blank, and if so return the home meta description.
It works fine - but I'm curious what others are doing.
// Add main site description on any page that doesn't have a customized description remove_action( 'genesis_meta', 'genesis_seo_meta_description' ); add_action( 'genesis_meta', 'wd_genesis_seo_meta_description' ); function wd_genesis_seo_meta_description() { global $wp_query; $description = ''; //* If we're on the home page if ( is_front_page() ) $description = genesis_get_seo_option( 'home_description' ) ? genesis_get_seo_option( 'home_description' ) : get_bloginfo( 'description' ); //* If we're on a single post / page / attachment if ( is_singular() ) { //* Description is set via custom field if ( genesis_get_custom_field( '_genesis_description' ) ) $description = genesis_get_custom_field( '_genesis_description' ); //* All-in-One SEO Pack (latest, vestigial) elseif ( genesis_get_custom_field( '_aioseop_description' ) ) $description = genesis_get_custom_field( '_aioseop_description' ); //* Headspace2 (vestigial) elseif ( genesis_get_custom_field( '_headspace_description' ) ) $description = genesis_get_custom_field( '_headspace_description' ); //* Thesis (vestigial) elseif ( genesis_get_custom_field( 'thesis_description' ) ) $description = genesis_get_custom_field( 'thesis_description' ); //* All-in-One SEO Pack (old, vestigial) elseif ( genesis_get_custom_field( 'description' ) ) $description = genesis_get_custom_field( 'description' ); } if ( is_category() ) { //$term = get_term( get_query_var('cat'), 'category' ); $term = $wp_query->get_queried_object(); $description = ! empty( $term->meta['description'] ) ? $term->meta['description'] : ''; } if ( is_tag() ) { //$term = get_term( get_query_var('tag_id'), 'post_tag' ); $term = $wp_query->get_queried_object(); $description = ! empty( $term->meta['description'] ) ? $term->meta['description'] : ''; } if ( is_tax() ) { $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $description = ! empty( $term->meta['description'] ) ? wp_kses_stripslashes( wp_kses_decode_entities( $term->meta['description'] ) ) : ''; } if ( is_author() ) { $user_description = get_the_author_meta( 'meta_description', (int) get_query_var( 'author' ) ); $description = $user_description ? $user_description : ''; } if ( is_post_type_archive() && genesis_has_post_type_archive_support() ) { $description = genesis_get_cpt_option( 'description' ) ? genesis_get_cpt_option( 'description' ) : ''; } //* If there is no description specified, used the home description by default if ( empty( $description ) ) { $description = genesis_get_seo_option( 'home_description' ) ? genesis_get_seo_option( 'home_description' ) : get_bloginfo( 'description' ); } //* Add the description if one exists if ( $description ) echo '<meta name="description" content="' . esc_attr( $description ) . '" />' . "\n"; }
It seems that maybe an option on the Genesis SEO Setting to use the home description as a fallback for any page without a customized description would be great.
Matt Whiteley – WhiteleyDesigns, GitHub
Designing, Developing & Creating with WordPressFebruary 17, 2015 at 1:45 am #141078LeifParticipantI use Yoast's plugin.
https://yoast.com/wordpress/plugins/seo/#title-descriptionWordPress SEO let’s you set templates for titles and meta descriptions for all types of pages, so you could come up with a template and not have to think about it, or you could use the WordPress SEO meta box to completely optimize your post title and meta description, using the snippet preview functionality to see what it would look like in Google
February 17, 2015 at 7:22 am #141092WhiteleyDesignsMemberHey Leif,
Thanks for the feedback. This is one of my go-to plug-ins for sure. I'd prefer to not use a plugin if possible, but you're right that this is the best solution currently.
Matt
Matt Whiteley – WhiteleyDesigns, GitHub
Designing, Developing & Creating with WordPressFebruary 18, 2015 at 3:15 pm #141245LeifParticipantSame here. Yoast is part of a short list of plugins I install on every site.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.