-
Hello,
I’m trying to update the custom fields “rank_math_title” and “rank_math_description” via the REST API using my admin account, but I keep receiving a 403 error stating that I’m not allowed to edit these fields.
I’m not very good at coding, but I added this code to my functions.php:
function register_rank_math_meta() { // Register Rank Math SEO Title register_meta( 'post', 'rank_math_title', array( 'object_subtype' => 'post', 'type' => 'string', 'single' => true, 'sanitize_callback' => 'sanitize_text_field', 'show_in_rest' => array( 'schema' => array( 'type' => 'string', 'description' => 'Rank Math SEO Title', 'context' => array( 'view', 'edit' ), ), 'auth_callback' => function() { return current_user_can( 'manage_options' ); }, ), ) ); // Register Rank Math SEO Description register_meta( 'post', 'rank_math_description', array( 'object_subtype' => 'post', 'type' => 'string', 'single' => true, 'sanitize_callback' => 'sanitize_text_field', 'show_in_rest' => array( 'schema' => array( 'type' => 'string', 'description' => 'Rank Math SEO Description', 'context' => array( 'view', 'edit' ), ), 'auth_callback' => function() { return current_user_can( 'manage_options' ); }, ), ) ); } add_action( 'init', 'register_rank_math_meta' );
Despite these changes, I still get the 403 error when updating the fields via the API. Could you please advise what I need to do to resolve this issue?
Thank you for your help.
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
The ticket ‘403 Error Updating Rank Math Custom Fields via REST API’ is closed to new replies.