- This topic has 5 replies, 2 voices, and was last updated 6 years, 11 months ago by Tom.
-
AuthorPosts
-
April 30, 2017 at 4:09 am #312174Iñigo García Aldazabal
Hello again.
Wordpress does not allow the picture caption of featured images to appear. But I needed it and changed the design of the posts:
In content, first again the featured image – now it shows captions – and then the text and more images.
Issue?
Now Google indexes the pages with a horrible look: the title of the post and in the description the picture caption and the signature of the author of the photograph.
I have searched and searched the internet and found a single reference to two possible solutions.
First, include the following code in the header.php:<Meta name = “description” content = “<? Php echo get_the_excerpt ();?>” /> ‘
Second, include the following code that generates a description field in each posts:
<? Php
If ((is_single ()) && (has_excerpt ())) {
$ D = get_the_excerpt ();
} Elseif (is_page ()) {
$ D = get_post_meta (get_the_ID (), ‘desc’, true);
}
If ($ d) {
$ D = preg_replace (“/<.*?>/”, “”, $ d);
Echo ‘<meta name = “description” content = “‘. $ D. ‘” />’;
}
?>But I have tried the latter and it does not work at all.
Any suggestions for Google to correctly index posts?
I would rather not add more plugins, Yoast style.
A cordial greeting.April 30, 2017 at 9:17 am #312236TomLead DeveloperLead DeveloperI know you said you don’t want to add Yoast, but it’s really the best option for things like this. There’s a reason it’s used by millions of WordPress website. It will help you achieve exactly what you’re wanting, and will also help in other ways as well (site maps etc..).
April 30, 2017 at 9:38 am #312249Iñigo García AldazabalIf you think Yoast is the best option, I’ll think about it. Only that I start to have too many plugins.
Just one last question. The code:<Meta name = “description” content = “<? Php echo get_the_excerpt ();?> “/> ‘
Do you think it can help?
If not, I follow your advice and install Yoast.
Thank you.April 30, 2017 at 9:40 am #312251TomLead DeveloperLead DeveloperThat used to be the norm, but these days Google actually grabs the description for you based on what the user searches.
Doing something like that should work in theory, but I wouldn’t really suggest it:
<meta name="description" content="<?php echo get_the_excerpt ();?>" />
Having too many plugins isn’t an issue as long as they’re well coded 🙂
April 30, 2017 at 9:57 am #312261Iñigo García AldazabalOkay. I’ll have to learn how to use Yoast.
Thank you very much.April 30, 2017 at 10:01 am #312263TomLead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.