Home › Forums › Pro Support › Changing image and excerpt source to use meta for some lists
- This topic has 11 replies, 2 voices, and was last updated 3 years, 7 months ago by
Tom.
-
AuthorPosts
-
August 11, 2019 at 1:50 am #10703
shpr
ParticipantHello,
could you tell me the function/hook I would need to have specific WP Show Posts lists use the following header meta (set via Yoast SEO) instead of the default?
* Image: <meta property=”og:image” content=”http://website.com/image.jpg”>
* Excerpt: <meta property=”description” content=”Blah blah…”>eg if I wanted lists 12345, 34567, 56789 to use this instead of the default.
Thanks
August 11, 2019 at 5:24 pm #10720Tom
KeymasterHi there,
How would the lists use this data, exactly?
August 12, 2019 at 12:01 am #10725shpr
ParticipantFor these lists the data would be used instead of the defaults ie.
* Instead of using the Featured Image from the post, it would use the image from meta property=”og:image”
* Instead of using the Content Excerpt from the post Excerpt, it use the content from meta property=”description”The reason is because a plugin I am using to generate Quizzes does not have a Featured Image, nor an Excerpt for each Quiz… WP Show Posts finds the Quiz posts OK and can list them, which is great… but ideally I’d like to display an image (and an excerpt if possible) and because it allows me to add the meta properties via Yoast I thought this might be the easiset way to accomplish it without amending the quiz plugin.
Thanks
August 12, 2019 at 5:04 pm #10751Tom
KeymasterIt might be possible if Yoast has a function we can use to get that data. You might want to see if their support can provide whether that’s possible/what the post meta names are. If we have that info, we can likely use hooks to output it in each post.
I took a quick look through their documentation but couldn’t find any info on getting that data.
August 18, 2019 at 3:05 am #10806shpr
ParticipantDidn’t get a reply from Yoast…but found these:
wpseo_opengraph_desc
wpseo_opengraph_imageAre they what I’m looking for?
Thanks
August 19, 2019 at 4:56 pm #10828Tom
KeymasterThose are filters, which isn’t quite what we’re looking for.
The meta name should be in the
wp_postmeta
table in your database under your specific post.September 14, 2019 at 11:11 am #11123shpr
ParticipantThanks for guidance. Looks like the meta names are:
_yoast_wpseo_opengraph-image
_yoast_wpseo_opengraph-descriptionSeptember 18, 2019 at 4:53 pm #11185Tom
KeymasterAwesome.
So on those lists, set your content type to “None”.
Then, do this:
add_action( 'wpsp_before_content', function( $settings ) { $targets = array( '12345', '34567', '56789', ); $content = get_post_meta( get_the_ID(), '_yoast_wpseo_opengraph-description', true ); if ( in_array( $settings['list_id'], $targets ) && $content ) { echo $content; } } );
So that should do the content.
For the featured images – do existing featured images exist?
September 22, 2019 at 6:58 am #11233shpr
ParticipantNo ‘featured image’ exists for the posts…this is my biggest problem.
Is it possible to get them from Yoast?
thanks
September 23, 2019 at 4:16 pm #11250Tom
KeymasterThat actually makes it easier:
add_action( 'wpsp_before_header', function() { if ( ! has_post_thumbnail() && get_post_meta( get_the_ID(), '_yoast_wpseo_opengraph-image', true ) ) { printf( '<div class="wp-show-posts-image"> <a href="%1$s"> <img src="%2$s" alt="" /> </a> </div>', get_permalink(), get_post_meta( get_the_ID(), '_yoast_wpseo_opengraph-image', true ) ); } } );
Let me know 🙂
October 19, 2019 at 9:08 am #11557shpr
ParticipantApologies for the slow reply – but THANK YOU for your patience and the code – it worked 🙂
October 21, 2019 at 5:55 pm #11590Tom
KeymasterYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.