Social Metadata Image Issue
-
Roland, the one i’m having trouble with is the og:image. When I do:
Participants_Db::files_uri() . $record->print_value('photo')
it’s pulling straight from the database and the path is not correct.
Here’s what it’s printing (which is not an image):
<meta property="og:image" content="https://tamuphysastr.wpengine.com/wp-content/uploads/directory/ryan_carmichael_science_4x4">
But the true path should be more like using
print_value('photo')
which spits out this long thing:
<meta property="og:image" content="<span class="pdbiex-image-field-wrap pdb-image pdbiex-image display-mode-image"><img src="https://tamuphysastr.wpengine.com/wp-content/uploads/directory/2019/07/ryan_carmichael_science_4x4-400x400.jpg" alt="ryan_carmichael_science_4x4" /></span>">
You can see my dilemma… even though this is a real image location, it has all the ugly html wrapped around it, so it won’t work. You can see I’ve got year/month added to the image path as well.
Do you have any sort of solution?
Thanks,
RyanThe page I need help with: [log in to see the link]
-
You need to add the plugin’s file location URL to the field value (which is simply the filename) to get your absolute URI for the image…like this:
<?php echo Participants_Db::files_uri() . $record->get_value('photo'); ?>
Sorry, that was a typo of mine above. I said I got the image value using:
Participants_Db::files_uri() . $record->print_value('photo')
When i’ve actually been using:
echo Participants_Db::files_uri() . $record->get_value('photo');
Which, as stated above, gives me a bad image URL:
<meta property="og:image" content="https://tamuphysastr.wpengine.com/wp-content/uploads/directory/ryan_carmichael_science_4x4">
Sorry for the confusion. Do you have a resolution? Thank you.
Are you using the image expansion kit add-on? That changes things a lot.
Yes, I am. 🙂 Love it by the way.
Right, so that will change how you need to the the URI because the image file is actually in the media library.
There is a helper function in the image expansion kit you can use for that:
<?php $uri = get_attachment_url_by_slug( $record->get_value('photo') ); <?
Roland, you’re awesome! 😀 That worked perfectly!!!
- The topic ‘Social Metadata Image Issue’ is closed to new replies.