1

I am trying to register a custom setting field in my WordPress dashboard using the following code:

function register_fields()
{

   register_setting('general', 'live_streaming_url', array(
     'show_in_rest' => true,
     'type' => 'string',
     'default' => 'public',
   ));
    add_settings_field('live_streaming_url', '<label for="live_streaming_url">'.__('Live 
    Streaming Link' , 'live_streaming_url' ).'</label>' , 'print_custom_field', 'general');
}

function print_custom_field()
{
    $value = get_option( 'live_streaming_url', '' );
    echo '<input type="text" id="live_streaming_url" name="live_streaming_url" style="width:250px;" value="' . $value . '" />';
}

add_filter('admin_init', 'register_fields');

The fields is working perfectly on the dashboard but it's not showing in the REST API when I call

http://MY_DOMAIN_NAME/wp-json/wp/v2/settings

Note: All the other fields are returned in the API expect that custom one.
Note: I am using WordPress 5.3.2

1 Answer 1

1

You need to add this script to make them appear in WP REST API

add_action('rest_api_init', 'register_fields'); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.