I need to add a new options to my settings, the new filed shown in settings page but not saved.

My add_settings_field callback:

  public function field_option_callback()
            <input type='checkbox' name='my_options[imgs][]' <?php checked( in_array( 'thumbnail', $imgs ), 1 ); ?> value='thumbnail'>
            <label><?php _e('Thumbnail','do'); ?></label>
        $html = "";
       echo apply_filters( 'after_options_callback', $html );

How I can add more fields and settings to my plugin using hooks?

EDIT: It works if I remove sanitize_callback from register_setting and use add_filter in same plugin file


You can use do_action( 'add_more_field', $post->ID, $post ); to extend fields

For more : https://developer.wordpress.org/reference/functions/add_action/

  • I did that already, but new fields not saved.
    – techno
    Mar 18 at 13:43
  • I think you've just added the input fields like shown above. but didn't save it. Hopefully, keeping all input name under "my_options" will solve the problem For example : if you want to add "subtitle" then input name should be my_options[subtitle] Mar 18 at 13:56
  • yes it have same name, it work if I put the code in same plugin file
    – techno
    Mar 18 at 14:02
  • Is the action name add_more_field correct? I can't find that one.
    – Rup
    Mar 19 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.