[Support request] Changing image and excerpt source to use meta for some lists

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Changing image and excerpt source to use meta for some lists

This topic contains 9 replies, has 2 voices, and was last updated by  Tom 3 weeks ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #10703

    shpr
    Participant

    Hello,

    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

    • This topic was modified 2 months ago by  shpr.
    #10720

    Tom
    Keymaster

    Hi there,

    How would the lists use this data, exactly?

    #10725

    shpr
    Participant

    For 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

    • This reply was modified 2 months ago by  shpr.
    #10751

    Tom
    Keymaster

    It 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.

    #10806

    shpr
    Participant

    Didn’t get a reply from Yoast…but found these:

    wpseo_opengraph_desc
    wpseo_opengraph_image

    via https://gist.github.com/amboutwe/811e92b11e5277977047d44ea81ee9d4#file-yoast_seo_opengraph_remove_subset-php

    Are they what I’m looking for?

    Thanks

    #10828

    Tom
    Keymaster

    Those 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.

    #11123

    shpr
    Participant

    Thanks for guidance. Looks like the meta names are:

    _yoast_wpseo_opengraph-image
    _yoast_wpseo_opengraph-description

    #11185

    Tom
    Keymaster

    Awesome.

    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?

    #11233

    shpr
    Participant

    No ‘featured image’ exists for the posts…this is my biggest problem.

    Is it possible to get them from Yoast?

    thanks

    #11250

    Tom
    Keymaster

    That 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 🙂

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.