• I need to create some display options in the editing interface to control the display of metabox, but I don’t know how to do it. According to the official website documents, I can get about add_screen_option and $screen->add_option, but I can’t create custom display options. What should I do?

    The main repo of the project is:

    [ redundant link removed ]

    • This topic was modified 6 years, 4 months ago by Jan Dembowski.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    To alter the display of your meta box on an admin screen, you’d need to largely rely upon JavaScript or jQuery to accomplish this. I don’t have any experience using the WP_Screen object. At best it’ll display an option and save the user selection, but since you’re not implementing core functionality, I’m unsure if it’ll even do that for you. In any case, altering the meta box display will be up to you JS code either way.

    If you have trouble with the WP_Screen object, I’d advise adding your option elements via JS as well. User selections can be saved to a cookie or user meta via Ajax.

    Thread Starter Chunhui Ouyang

    (@jack960330)

    How to add option elements through JS, are there any examples?

    Moderator bcworkz

    (@bcworkz)

    Use your browser’s element inspector developer tool to learn what DOM element you would want to add a node (your field label and field) to. Add it like we would add any HTML element to the DOM. Naturally you should mimic the structure used by WP elements.

    WP knows nothing of this added element, you need to handle user interaction yourself. This is nothing new if you want the user interaction to affect appearance on the page. The difference is the user selection will not be saved unless you do so yourself.

    Thread Starter Chunhui Ouyang

    (@jack960330)

    In this way, more work may need to be done. Maybe I should put this part to the end. Now metabox and processing logic need to be solved first!

    Moderator bcworkz

    (@bcworkz)

    Indeed. A nice UI seems to always involve more work. If you’re more comfortable with PHP than JS, you could perhaps place the screen controls you want right in the meta box. They can always be moved to the screen tab at a later date.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘How to create display options for screen’ is closed to new replies.