This support ticket is created Il y a 2 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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
Tell us what you are trying to do?
I want to use an image from a custom field as meta property
What is the link to your site? lien caché
I saw: <meta property="og:url" content="<?php do_shortcode('[types field='affiliate-url' output='raw'][/types]'); ?>" /> but I don't know where to put it....
I found single.php, header.php and dynamic-header.php, i tried to put the code " <meta property="og:image" content="<?php echo types_render_field('image-a-mettre-a-la-une', array()) ?>" />" in all of theme without success...
Is there a way to make it with a php code in function.php ?
//Adding the Open Graph in the Language Attributes
function add_opengraph_doctype( $output ) {
return $output . ' xmlns:og="<em><u>lien caché</u></em>" xmlns:fb="<em><u>lien caché</u></em>"';
}
add_filter('language_attributes', 'add_opengraph_doctype');
//Lets add Open Graph Meta Info
function insert_fb_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
$default_image="<?php echo types_render_field('image-a-mettre-a-la-une', array()) ?>"; //replace this with a default image on your server or an image in your media library
echo '<meta property="og:image" content="' . $default_image . '"/>';
}
else{
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
}
echo "
";
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );
function insert_fb_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
$default_image="<?php do_shortcode('[types field='your-custom-code' output='raw'][/types]'); ?>"; //replace this with a default image on your server or an image in your media library
echo '<meta property="og:image" content="' . $default_image . '"/>';
}
else{
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
}
echo "
";
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );
it worked but only once.... im so disapointed :-[ but how can i make it work, and another question can i make it work only for a specific post type....