Skip to content

Settings API: Add ID attributes to section title headings. - #11472

Closed
rakeshf wants to merge 4 commits into
WordPress:trunkfrom
rakeshf:add/settings-section-id-anchors
Closed

Settings API: Add ID attributes to section title headings.#11472
rakeshf wants to merge 4 commits into
WordPress:trunkfrom
rakeshf:add/settings-section-id-anchors

Conversation

@rakeshf

@rakeshf rakeshf commented Apr 8, 2026

Copy link
Copy Markdown

Ticket Details: https://core.trac.wordpress.org/ticket/65027

The main motivation for doing that is to allow hash navigation via URL. We could easily in the documentation have links such as wp-admin/options-discussion.php#avatars, which I think it is a huge benefit if we're talking long forms.

@github-actions

github-actions Bot commented Apr 8, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @rakeshfalke99.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

Core Committers: Use this line as a base for the props when committing in SVN:

Props joedolson, afercia.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Apr 8, 2026

Copy link
Copy Markdown

Hi @rakeshf! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

@github-actions

github-actions Bot commented Apr 8, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@joedolson joedolson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add a prefix to these ID attributes, as the relatively generic IDs like avatar could be in use already be extenders. Something like wp-settings- would help ensure that they don't overlap with existing IDs.

Comment thread src/wp-admin/includes/template.php Outdated

@joedolson joedolson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought to consider.

Comment thread src/wp-admin/includes/template.php Outdated

if ( $section['title'] ) {
echo "<h2>{$section['title']}</h2>\n";
echo '<h2 id="wp_section_' . esc_attr( $section['id'] ) . '">' . $section['title'] . "</h2>\n";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative, this could use

$unique_id = wp_unique_id( 'wp_section_' . $section['id'] . '-' );

This has the benefit of avoiding duplicate IDs.

@afercia afercia Jul 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on using wp_unique_id. I'm not sure the ID should use underscores. I think the best practice in WordPress is using dashes?

@afercia
afercia force-pushed the add/settings-section-id-anchors branch from a6055c5 to f5f9583 Compare July 9, 2026 13:49
@afercia
afercia force-pushed the add/settings-section-id-anchors branch from f5f9583 to 5144d56 Compare July 9, 2026 13:51
@afercia

afercia commented Jul 9, 2026

Copy link
Copy Markdown
Member

I pushed two commits:

  1. Uses wp_unique_id with a prefix that is made of a string wp-settings-section- + the section ID.
  2. For the core settings H@ headings, I just prepended wp-settings-section- to the IDs added in this PR.

To quickly test the Settings API you can temporarily add this snippet in the options-reading.php file:


add_settings_section( 'awesome-avatars', 'My avatars section title', '__return_false', 'andreatest' );
add_settings_field(
	'color_scheme',
	__( 'Color Scheme' ),
	'__return_false',
	'reading',
	'andreatest'
);
do_settings_sections( 'andreatest' );

add_settings_section( 'nice-icons', 'My icons section title', '__return_false', 'andreatest2' );
add_settings_field(
	'color_scheme',
	__( 'Color Scheme' ),
	'__return_false',
	'reading',
	'andreatest2'
);
do_settings_sections( 'andreatest2' );

It will add two section headings. The IDs on the headings will be:

  • wp-settings-section-awesome-avatars-1
  • wp-settings-section-nice-icons-2

@joedolson joedolson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 62710
GitHub commit: 446655f

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants