Truncate manually entered SEO descriptions

Need help with this?
Purchase All in One SEO Pack Pro to get dedicated support from us.

Buy Now

In version 2.4.4 of All in One SEO Pack and version 2.5.4 of All in One SEO Pack Pro we added support for the new longer 320 character descriptions that Google may use in search results.

Some users may prefer to truncate their descriptions to something other than the 320 character limit set by All in One SEO Pack.  The filter code below can be used to do this:

add_filter( 'aioseop_description', 'manual_description_force_truncate_3', 9, 2 );
function manual_description_force_truncate_3( $description, $truncate = false ) {
	global $post;

	$aioseop_desc = '';
	if ( is_front_page() || is_single() || is_page() || is_attachment() || is_home() ) {
		if ( ! empty( $post->ID ) ) {
			$aioseop_desc = get_post_meta( $post->ID, '_aioseop_description', true );
		}

		if ( ! empty( $aioseop_desc ) ) {
			$description = substr( $description, 0, 320 );
		}
	} else if ( is_category() || is_tag() || is_tax() ) {
		if ( AIOSEOPPRO ) {
			$queried_object = get_queried_object();
			$term_meta = '';
			if ( ! empty( $queried_object ) && ! empty( $queried_object->term_id ) ) {
				$term_meta = get_term_meta( $queried_object->term_id, '_aioseop_description', true );
			}
			if ( ! empty( $term_meta ) ) {
				$description = substr( $description, 0, 320 );
			}
		}
	}

	return $description;
}
[i]
[i]
Skip to toolbar