interation opengraph
This commit is contained in:
@@ -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);
|
||||
Reference in New Issue
Block a user