Skip to content

Instantly share code, notes, and snippets.

@giacomolanzi
Last active May 1, 2025 11:18
Show Gist options
  • Save giacomolanzi/c4d802476be4f4adad6b0819399ecc1b to your computer and use it in GitHub Desktop.
Save giacomolanzi/c4d802476be4f4adad6b0819399ecc1b to your computer and use it in GitHub Desktop.
Add RankMath meta field to REST API
<!-- This exposes the following meta field to posts in REST API: rank_math_focus_keyword, rank_math_title, rank_math_description -->
function register_rank_math_custom_fields_rest_api()
{
$meta_keys = [
'rank_math_focus_keyword',
'rank_math_title',
'rank_math_description'
];
foreach ($meta_keys as $meta_key) {
register_meta('post', $meta_key, [
'type' => 'string',
'description' => 'Campo Rank Math personalizzato',
'single' => true,
'show_in_rest' => true,
'auth_callback' => function () {
return current_user_can('edit_posts');
}
]);
}
}
add_action('init', 'register_rank_math_custom_fields_rest_api');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment