interation opengraph

This commit is contained in:
sebvtl728
2025-01-15 09:50:46 +01:00
parent 7c25479236
commit a9f17ff11f
7 changed files with 5105 additions and 51 deletions
@@ -161,4 +161,25 @@ register_rest_field(
},
'schema' => null,
]
);
);
function ajouter_opengraph_meta_api($data, $post, $context) {
if ($context !== 'view' || !$post) {
return $data;
}
// Récupérer les métadonnées de Rank Math
$og_title = get_post_meta($post->ID, 'rank_math_title', true);
$og_description = get_post_meta($post->ID, 'rank_math_description', true);
$og_image = get_post_meta($post->ID, 'rank_math_facebook_image', true);
// Ajouter les métadonnées au champ API
$data->data['opengraph'] = [
'title' => $og_title ?: $post->post_title,
'description' => $og_description ?: wp_trim_words($post->post_content, 20),
'image' => $og_image ? wp_get_attachment_url($og_image) : null,
];
return $data;
}
add_filter('rest_prepare_post', 'ajouter_opengraph_meta_api', 10, 3);