• Howdy,

    iv noticed some confusion over the $id attribute, some guides seem to match the html id value and some guides seem to match every additional add_settings_fields to the $option_name within register_settings?? why would they do this???

    register_setting(‘$option_group’ $option_name);

    i hope someone can clear up the correct way to address the $id

    thankyou in advance

    below is from the official explanation:
    add_settings_field( string $id, string $title, callable $callback, string $page, string $section = ‘default’, array $args = array() )

    $id
    (string) (Required) Slug-name to identify the field. Used in the ‘id’ attribute of tags.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p

    (@t-p)

    Thread Starter Simon Barlcay

    (@primerepair)

    thanks but that’s the official explanation as i noted, however this guide falls short in explaining the exact specific ‘id’ this is required, it says ‘slug name’? what slug name? what for? there is also differences with opinions on other sites, does anyone know? should it match the html id attribute? are their any other considerations as to what this ‘id’ may do or not do? can it collide with other plugin’s if not registered correctly and uniquely?

    Moderator bcworkz

    (@bcworkz)

    It’s an arbitrary name that should follow slug naming convention – all lowercase, only alphanumeric and - characters. To avoid name collisions, prefix the slug with your, your plugin’s or theme’s, initials. For example, I might prefix slugs with “bcw” (from “bcworkz”), e.g. “bcw-twitter-handle”.

    The ID is used when you register the setting, the “option_name”. Yes, that is indeed confusing. It’s also used as the HTML tag’s ID attribute, and is used internally to save the associated value on submission.

    The old Codex page has examples that might help you understand the Settings API.

    Thread Starter Simon Barlcay

    (@primerepair)

    Thanks very much bcworkz for the explanation, perfect will take a look at the link… thankyou

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘add_settings_fields’ is closed to new replies.