WordPress assign H1 tag to Menu - can I stop it?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

WordPress assign H1 tag to Menu - can I stop it?

Post by simonmlewis »

Code: Select all

<div id="header-right-section">
												<nav id="site-navigation" class="main-navigation" role="navigation">
							<h1 class="menu-toggle">Menu</h1>
							<div class="menu-main-container"><ul id="menu-main" class="menu"><li id="menu-item-6515" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-6515"><a title="Home" href="http://site.co.uk/">Home</a></li>
<li id="menu-item-6329" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor menu-item-has-children menu-item-6329"><a href="http://site.co.uk/about-us/">About Us</a>
This is within my rendered HTML, and some software says I have too many H1 tags, and it's clear as to why.
Firstly in WordPress it was assigning a <h1> tag to the site title. I've removed that.

But now it's also assigning it to the Menu, which I think is for mobile only.

SEO wise... it's daft. But I don't see a way to take it off. If I change it to <div class="menu-toggle"> it's likely to break isn't it?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: WordPress assign H1 tag to Menu - can I stop it?

Post by Celauran »

simonmlewis wrote:If I change it to <div class="menu-toggle"> it's likely to break isn't it?
You'd need to check the related JS and CSS. It certainly isn't going to break in any way that's difficult to fix.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: WordPress assign H1 tag to Menu - can I stop it?

Post by simonmlewis »

It's just part of the general CSS and Javascript I think, how most WP mobile menus work, but I cannot see the Javascript file that runs it.
If I change it from H1 to DIV, it loses a lot of padding, but the "link" to make the menu dropdown on mobile doesn't expand.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: WordPress assign H1 tag to Menu - can I stop it?

Post by simonmlewis »

Found it.

Code: Select all

/**
 * navigation.js
 *
 * Handles toggling the navigation menu for small screens.
 */
( function() {
	var container, button, menu;

	container = document.getElementById( 'site-navigation' );
	if ( ! container )
		return;

	button = container.getElementsByTagName( 'h1' )[0];
	if ( 'undefined' === typeof button )
		return;

	menu = container.getElementsByTagName( 'ul' )[0];

	// Hide menu toggle button if menu is empty and return early.
	if ( 'undefined' === typeof menu ) {
		button.style.display = 'none';
		return;
	}

	if ( -1 === menu.className.indexOf( 'nav-menu' ) )
		menu.className += 'nav-menu';

	button.onclick = function() {
		if ( -1 !== container.className.indexOf( 'main-small-navigation' ) )
			container.className = container.className.replace( 'main-small-navigation', 'main-navigation' );
		else
			container.className = container.className.replace( 'main-navigation', 'main-small-navigation' );
	};
} )();
So how do I set this to work with a div. Do I just change the "h1" to be a DIV instead?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: WordPress assign H1 tag to Menu - can I stop it?

Post by Celauran »

What happened when you tried?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: WordPress assign H1 tag to Menu - can I stop it?

Post by simonmlewis »

I'm having difficulties accessing FTP. Seems you cannot alter it within WP itself.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: WordPress assign H1 tag to Menu - can I stop it?

Post by simonmlewis »

No that didn't work.
I changed it to h1 in both the header and navigation.js file and it failed to work.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: WordPress assign H1 tag to Menu - can I stop it?

Post by Celauran »

Is this one of the default WP themes (or a child thereof) or is it a custom theme?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: WordPress assign H1 tag to Menu - can I stop it?

Post by simonmlewis »

Spacious Pro. I didn't install it. So not sure.
I have downloaded it all to my machine. CAn you remind me in what file I change or add a line to stop it chucking me out of local and onto the live .co.uk when I go to wp-admin.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: WordPress assign H1 tag to Menu - can I stop it?

Post by simonmlewis »

ignore last message about accesing wp-admin, i'm in.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: WordPress assign H1 tag to Menu - can I stop it?

Post by simonmlewis »

It did work. That was odd. Well it's worked locally anyway.
Thanks.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply