Last active
May 1, 2025 11:18
-
-
Save giacomolanzi/c4d802476be4f4adad6b0819399ecc1b to your computer and use it in GitHub Desktop.
Add RankMath meta field to REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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