Page 1 of 1

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

Posted: Mon Jun 08, 2015 5:47 am
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?

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

Posted: Mon Jun 08, 2015 6:42 am
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.

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

Posted: Mon Jun 08, 2015 7:08 am
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.

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

Posted: Mon Jun 08, 2015 7:11 am
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?

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

Posted: Mon Jun 08, 2015 7:26 am
by Celauran
What happened when you tried?

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

Posted: Mon Jun 08, 2015 7:29 am
by simonmlewis
I'm having difficulties accessing FTP. Seems you cannot alter it within WP itself.

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

Posted: Mon Jun 08, 2015 8:08 am
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.

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

Posted: Mon Jun 08, 2015 8:17 am
by Celauran
Is this one of the default WP themes (or a child thereof) or is it a custom theme?

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

Posted: Mon Jun 08, 2015 8:22 am
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.

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

Posted: Mon Jun 08, 2015 8:24 am
by simonmlewis
ignore last message about accesing wp-admin, i'm in.

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

Posted: Mon Jun 08, 2015 8:39 am
by simonmlewis
It did work. That was odd. Well it's worked locally anyway.
Thanks.