pennywise
pennywise

Reputation: 149

Display meta description outside single post - WordPress

This is my first question here, hope to be useful in future to someone. We work on a WordPress site now, and try to display meta description content generated by All In One Seo plugin outside the loop. It's not a problem when it's on page/post. The code that works for single is

<?php $metadesc = get_post_meta($post->ID, '_aioseop_description', true);
if ($metadesc) {
echo $metadesc;
} else {
the_excerpt();
}
?>

Later on the other day I came with this solution

<?php $mykey_values = get_post_custom_values('_aioseop_description'); 
foreach ( $mykey_values as $key => $value ) {
echo "$value"; 
 } ?>

I'm not sure if it's good to use this one, the problem I have now is that I want to display exact number of symbols, not all the content.

Upvotes: 1

Views: 1882

Answers (1)

pennywise
pennywise

Reputation: 149

Well it was pretty lame question, but sometimes when you are stuck it's hard to see simple things. This is my final code which do the work for me:

<?php $mykey_values = get_post_custom_values('_aioseop_description');
foreach ( $mykey_values as $key => $value ) {
echo substr("$value",0 ,150); //This will display the first 150 symbols
} ?>

Upvotes: 1

Related Questions