Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The h4 headings are not listed in the toc generated #4

Open
mrwindowsx opened this issue May 3, 2021 · 3 comments · May be fixed by #7
Open

The h4 headings are not listed in the toc generated #4

mrwindowsx opened this issue May 3, 2021 · 3 comments · May be fixed by #7

Comments

@mrwindowsx
Copy link

The TOC only generate the h3 headings tag, the h4 headings are not listed in the TOC generated

@trepmal
Copy link
Contributor

trepmal commented May 25, 2021

Confirmed.

Initially, it looked like h4s headings might have been a fallback, as they will appear if there are no h3s. However a closer look shows this is a bug for sure.

$items = $h3s + $h4s;

This union operator means a) we'll end up with a weird TOC if there are more h4s than h3s and b) the original order won't be maintained.

I'm working on a few general updates in my fork, here's a changeset that will make the headings used for the TOC filterable.

In my fork, h3 is kept as the default heading to use in the TOC. h4s are ignored altogether. To add additional headings, a filter can be used:

add_filter( 'toc_tags_for_toc', function( $tags) {
	return [ 'h3', 'h4' ];
}, 11 );

If you have a chance to test out my change, that would be great! I'll work on getting my fork's updates merged over here properly.

@trepmal trepmal linked a pull request May 25, 2021 that will close this issue
@mrwindowsx
Copy link
Author

Hi, thanks for this fix, however, this fix only worked when there is no Gutenberg align style applied on the headings, for example, when you add heading h3 and change the block align style into a center, this TOC won't generate this heading, this also same when you add these headings into a group block.

@trepmal
Copy link
Contributor

trepmal commented Jun 2, 2021

I think that's technically a separate issue, so I've created issue #10 to track that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants