Skip Navigation

[Résolu] Setting open graph properties from custom fields to templates

This support ticket is created Il y a 5 années et 7 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 réponses, has 2 voix.

Last updated by Luo Yang Il y a 5 années et 6 mois.

Assisted by: Luo Yang.

Auteur
Publications
#1123947

Support,

What is the best way to set og data so sites link Facebook do a proper pull?

Can I simply drop each og field in my template like this: <h4 class="posttitle" meta-property="og:title">[wpv-post-title]</h4>
or do i need to do further coding?

Thanks,
Charles

#1124309

Dear Charles,

I assume we are talking about the "Open Graph protocol":
hidden link

If it is, according to above document, you will need to generate some meta codes using custom PHP codes, for example:

<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="<em><u>hidden link</u></em>" />
<meta property="og:image" content="<em><u>hidden link</u></em>" />

In a single post, you can use WordPress action hook "wp_head" to trigger a PHP function:
https://developer.wordpress.org/reference/hooks/wp_head/

Output the HTML codes as below:

1) og:title, you can use the post title, function get_the_title():
https://developer.wordpress.org/reference/functions/get_the_title/

2) og:type, you can setup a custom select field, render the value with Types function types_render_field()
https://toolset.com/documentation/customizing-sites-using-php/functions/

3) og:url, try the function get_permalink():
https://developer.wordpress.org/reference/functions/get_permalink/

4) og:image, try the function get_the_post_thumbnail_url():
https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/

For your reference

#1125589

Heading in the right direction.
How would I go about pulling the info from custom fields?
Like:

<meta property="og:title" content=[wpv-post-title] />
<meta property="og:type" content="article" />
<meta property="og:url" content=[types field='affiliate-url' output='raw'][/types] />
<meta property="og:image" content=[types field='product-image' output='raw'][/types] />

Thanks,
Charles

#1125849

As I mentioned above, you can try Types API function types_render_field()
https://toolset.com/documentation/customizing-sites-using-php/functions/

Or wordpress built-in function get_post_meta():
https://codex.wordpress.org/Function_Reference/get_post_meta

Or use function do_shortcode() to render the shortcode, for example:

<meta property="og:url" content="<?php do_shortcode('[types field='affiliate-url' output='raw'][/types]'); ?>" />

https://developer.wordpress.org/reference/functions/do_shortcode/

#1126322

So something like this:
<cpde>
<meta property="og:title" content="<?php do_shortcode('[wpv-post-title]'); ?>" />
<meta property="og:type" content="website" />
<meta property="og:url" content="<?php do_shortcode('[types field='affiliate-url' output='raw'][/types]'); ?>" />
<meta property="og:image" content="<?php do_shortcode('[types field='product-image' output='raw'][/types]'); ?>" />
<meta property="og:description" content="<?php do_shortcode('[types field='product-description' output='raw'][/types]'); ?>" />
[/php]

And I'm placing this where? Header, multiple places, or another?

Sorry, PHP is not my strong suit.

Thanks,
Chuck

#1127277

Since it is a custom PHP codes problem, please provide a test site with the same problem, and fill below private message box with credentials and FTP access, also point out the problem page URL and where I can edit your PHP codes, I need a live website to test and debug

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.