• Resolved harjapaa

    (@harjapaa)


    Hello,

    is it possible to default the og:image for a single post as the set featured image of the post?

    • This topic was modified 2 years, 4 months ago by harjapaa.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    TSF already automatically uses the post’s featured image for social sharing as the primary fallback.

    TSF selects an image in this order:
    1. A manually entered custom image.
    2. Featured image.
    3. If WooCommerce Product, try from product Gallary.
    4. Applicable images from the content.
    5. Custom fallback image set at the SEO Settings.
    6. Site header image.
    7. Site logo.
    8. Site icon.

    Is this not working correctly on your site?

    Thread Starter harjapaa

    (@harjapaa)

    Sorry, I accidentally gave you wrong information. I’m working on behalf of my client, and it turned out it’s not an actual “Featured image” per se, it’s an ACF field to serve a similar purpose. Is there a chance to somehow use that one instead?

    Plugin Author Sybre Waaijer

    (@cybr)

    Howdy!

    Yes, that’s possible via a filter. Here’s an example; it’s pretty involved since it works inside a generator’s coroutine to improve performance: https://gist.github.com/sybrew/57dd909654edefd3871095fb0e4bf137.

    If you wish assistance building the filter to your requirements, let me know the field name, and I can alter it accordingly. Let me know if the field ID consists of an image ID and URL or just a URL.

    Thread Starter harjapaa

    (@harjapaa)

    Hi!

    Brilliant, thank you! If you could help with building the filter, that would be great!

    It’s an ACF image field, Return Format: Image Array, Field Name: “post-image”. Thank you very much! Below is a screenshot from that particular field’s settings.

    https://media.discordapp.net/attachments/268676108780568576/1205519897426395166/image.png?ex=65d8aae5&is=65c635e5&hm=c21e243a80e362abd141fb396c204a49401bfb9a63f4cc73665c0b6296c28cdd&=&format=webp&quality=lossless&width=892&height=536

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi again!

    It took a bit longer than I’d had hoped, but here it is:
    https://gist.github.com/sybrew/94d779044a0a8b9bb31fd90c7d74c8ea

    Let me know if it works as intended and if there’s anything else I can do for you. Have a lovely week!

    Thread Starter harjapaa

    (@harjapaa)

    Hi Sybre,

    thank you, I can confirm it works perfectly! In my snippet plugin, I needed to set this code to work in front-end only, as it somehow broke the adding of the image in back-end, but that’s ok.

    Thanks a lot, and have a great week too!

    Thread Starter harjapaa

    (@harjapaa)

    It turned out the code had some issues/mistyped function names we had to switch to get it working

    We had to change the second function name to “my_custom_tsf_acf_singular_image_generator” (since that is what is referenced in the first function).

    And in the second function had to change:
    $image = get_field( 'post-image', $args['id'] ?? tsf()->query()->get_the_real_id() );
    to
    $image = get_field( 'post-image', $args['id'] ?? the_seo_framework()->get_the_real_ID() );
    since the original tsf()->query() returned null and therefore gave fatal error

    With these changes seems to now work perfectly.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    First, thank you for the lovely review 😊!

    That callback name oversight shouldn’t have happened — I edited the name last-second inside the gist-posting window; my real editor would’ve highlighted all names on a bigger screen and has tools to do it better (CTRL+H). I should’ve tested it, but replicating an ACF setup is quite tedious. It also didn’t help I was tired. Sorry about that!

    The other issue is that your site is still on TSF v4.2 or lower. In TSF v5.0, I deprecated tsf()->get_the_real_ID() in exchange for tsf()->query()->get_the_real_id(). I also added the The_SEO_Framework\get_query_type_from_args() function-call to ease using $args in the admin area: the snippet should’ve worked on both the front-facing pages and the admin area, but this missing function made your site crash in the admin area.

    If I’m not provided with the plugin information, I must assume the person reaching out uses the most up-to-date version. This saves me a headache, especially since there were over 1200 changes.

    If you haven’t yet updated, please see if you can. Note that TSF v5.0 requires PHP 7.4 or higher. Aside from 2 hiccoughs I still need to address (Polylang support and link-rel option listeners), everything is simply better — especially the APIs.

    I just updated the gist with the naming fix (and a code style fix), but it still requires TSF v5.0 or later.

    Let me know if there’s anything else I can help you with. Have a beautiful day!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Featured image as og:image’ is closed to new replies.