Container Tag to nav

I see that I can set div, article, section, header, footer and even aside tags to a container. But is there a filter or way that I can set it to nav tag?

What I am trying to do here is to create a Table of Contents block with a custom list. <nav> markup helps in SEO.

There’s a filter.

Example:

add_filter('generateblocks_container_allowed_tagnames', function( $tagnames, $attributes, $block){
	if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'cu-nav-cont' ) !== false ) {
		return array(
				'div',
				'article',
				'section',
				'header',
				'footer',
				'aside',
				'a',
			    'nav',
			);
	}
	return $tagnames;
}, 3, 10);


add_filter('generateblocks_container_tagname', function( $tagname, $attributes, $block){
	if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'cu-nav-cont' ) !== false ) {
		return 'nav';
	}
	return $tagname;
}, 3, 10);

You just need to give the Container a class of cu-nav-cont.

See Jean’s reply here though: Add more tag names for container · Issue #750 · tomusborne/generateblocks · GitHub

In the future, the team is planning to add more flexibility.

Awesome. Totally works. :slight_smile: Thanks @fernandoazarcon2

You’re welcome, @gauravtiwari!