When running a Lighthouse check on my site, I received the following error under SEO:
Links are not crawlable
Search engines may use
href
attributes on links to crawl websites.
Ensure that thehref
attribute of anchor elements links to an
appropriate destination, so more pages of the site can be discovered.
Learn More
The link that could not be crawled is a#main-content
, which is the «Skip to main content» link.
This is the page’s HTML:
<a href="#main-content" class="visually-hidden focusable"> Skip to main content </a>
..navbar..
<a id="main-content" tabindex="-1"></a>
As far as I know, this structure is completely fine and doesn’t present any real problems for Google or any other search engine. So what’s the best way to address this error for this specific link?
I am trying to automate the Lighthouse reports in my CI pipeline, and I want to minimize the number of known errors.
asked Dec 13, 2020 at 3:09
1
For this problem in Lighthouse 7.1.0, I use
<span id="main-content" tabindex="-1"></span>
and it works fine.
answered Mar 16, 2021 at 20:46
2
It seems that Lighthouse only complains if <a>
is missing href
, even if that link is marked nofollow, so one way to fix this is to point the «Skip to main content» link at something other than <a>
.
Before:
<a id="main-content" tabindex="-1"></a>
After:
<main role="main" id="main-content">
Normally I would avoid workarounds to match the eccentricities of the evaluation tool, but in this case it’s only one change for one link on a site with hundreds of pages.
answered Dec 13, 2020 at 10:11
Why did you get this warning?
Lighthouse tests for onclick="window.open
to try and catch anchors that are activated by JavaScript instead of a href
, as this is bad for SEO and accessibility.
Fixes / suggestions
If your href
was valid I would say you could safely ignore this but it is not valid (empty «u» and «t» parameters).
Fix your href
so that it is valid (build it server-side to populate the u
and t
parameters), you will still get the warning but it can be safely ignored then.
Although saying that if you fix the URL then target="_blank"
will open the sharer in a new tab so that would be sufficient without the need for any JavaScript.
To remove the error you should move the event handler into a JavaScript file rather than using inline onclick
handlers.
This will remove the warning after looking at the audit source code and is a good practice.
You can do this easily with target.addEventListener
.
Quick example of event listeners
const el = document.getElementById("fbLink");
el.addEventListener("click", sharerFunction, false);
function sharerFunction(e){
e.preventDefault();
window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(document.URL) + '&t=' + encodeURIComponent(document.URL));
alert("link will not open due to sandbox permissions, but check console it does fire");
}
<a href="https://facebook.com" id="fbLink" ....**other stuff here**....>Facebook icon</a>
Relevant part of audit source code for reference
As mentioned earlier the source code for the crawlable-anchors test shows what is tested for, anything returning true
is a fail, notice how the hasClickHandler
test returns null
as that is considered ok (I believe, it is late I may have misread the code!).
const windowLocationRegExp = /window.location=/;
const windowOpenRegExp = /window.open(/;
const javaScriptVoidRegExp = /javascript:void((|)0()|)/;
if (rawHref.startsWith('file:')) return true;
if (windowLocationRegExp.test(onclick)) return true;
if (windowOpenRegExp.test(onclick)) return true;
const hasClickHandler = listeners.some(({type}) => type === 'click');
if (hasClickHandler || name.length > 0) return;
if (rawHref === '') return true;
if (javaScriptVoidRegExp.test(rawHref)) return true;
Skip to content
Support » Theme: Neve » Links are not crawlable
-
Hello,
I have just set up the theme Neve and Lighthouse reports me some problems about SEO. One is aboutLinks are not crawlable
Search engines may usehref
attributes on links to crawl websites. Ensure that thehref
attribute of anchor elements links to an appropriate destination, so more pages of the site can be discovered. Learn More
Uncrawlable Link
aCould you help me to solve? All the articles have this problem.
The page I need help with: [log in to see the link]
Viewing 3 replies — 1 through 3 (of 3 total)
-
Ok thanks a lot.
And where can I copy this code?<a class=”crunchify-link crunchify-facebook”
href=”https://www.facebook.com/sharer/sharer.php?u=&t=”
title=”Share on Facebook”
rel=”noopener”
target=”_blank”
onclick=”window.open(‘https://www.facebook.com/sharer/sharer.php?u=’ + encodeURIComponent(document.URL) + ‘&t=’ + encodeURIComponent(document.URL)); return false;”
>
<div class=”facebook-ic”></div>Do I change something in this code?
Martina
Hi @madieginger,
I’ve tried to check your website (homepage and post page) and I don’t see this notification about the href attributes missing.
Could you provide the URL of the exact page where this issue is present and also a screenshot of the report with that issue (the text that you copy/pasted in the original message of this thread).
Thanks!
Viewing 3 replies — 1 through 3 (of 3 total)
- The topic ‘Links are not crawlable’ is closed to new replies.
- Neve
- Support Threads
- Active Topics
- Unresolved Topics
- Reviews
- In: Themes and Templates
- 3 replies
- 3 participants
- Last reply from: Vytis
- Last activity: 1 year, 11 months ago
- Status: resolved
Views
- Topics with no replies
- Non-support topics
- Resolved topics
- Unresolved topics
- All topics
Viewing 5 replies — 1 through 5 (of 5 total)
I found the following solution from another wordpress support page Uncrawlable Link from UM on every page of website
Problem is it solves the issue for all pages except user page. And for a personal like me, whose site has 500 users, it means 500 urls still have content that is uncrawlable.
Please support and provide us with a real solution for a real problem and mend it in future version of UM.
I have been UM customer since 3rd May 2018, and noticed this error for the first time yesterday, Imagine how many people would be their who wouldn’t even notice and never even try to fix this issue.
Hi @adityamilyin
You can copy the template ultimate-member/templates/modal/um_view_photo.php
and then modify the copy with your preferred attributes with the anchor and then remove the existing template with the code below.
add_action("template_redirect", function(){
remove_action( 'wp_footer', array( UM()->modal(), 'load_modal_content'
});
And if you don’t want to display this um_view_photo template for non-logged-in user, just use the following:
add_action("template_redirect", function(){
if( ! is_user_logged_in() ){
remove_action( 'wp_footer', array( UM()->modal(), 'load_modal_content' ), 9 );
}
});
Regards,
Great.
Thanks for the snippet to remove actions for modal, however I would prefer to solve the error rather than just hide it for logged out users.
I tried to copy and paste the file, to /wp-content/themes/milyin/ultimate-member/templates/ and changes made weren’t shown on frontend.
I tried to copy and paste the file to /wp-content/themes/milyin/ultimate-member/templates/modal/ changes made there weren’t shown either.
Please inform me the correct directory,
Also suggest the changes that need to be made to the template to achieve the desired results in Lighthouse.
Thanks in Advance
Hi @adityamilyin
You need to include a copy of the template file that has changes to match your desired result. You will need to customize it on your end.
Just include the template like this( it depends where you locate the copy of the template ):
add_action( 'wp_footer', function(){
include_once "path/wp-content/themes/your-theme/ultimate-member/modal/um_view_photo.php"
});
Regards,
Hi @adityamilyin
Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. 🙂
Regards,
Viewing 5 replies — 1 through 5 (of 5 total)
Viewing 5 replies — 1 through 5 (of 5 total)
I found the following solution from another wordpress support page Uncrawlable Link from UM on every page of website
Problem is it solves the issue for all pages except user page. And for a personal like me, whose site has 500 users, it means 500 urls still have content that is uncrawlable.
Please support and provide us with a real solution for a real problem and mend it in future version of UM.
I have been UM customer since 3rd May 2018, and noticed this error for the first time yesterday, Imagine how many people would be their who wouldn’t even notice and never even try to fix this issue.
Hi @adityamilyin
You can copy the template ultimate-member/templates/modal/um_view_photo.php
and then modify the copy with your preferred attributes with the anchor and then remove the existing template with the code below.
add_action("template_redirect", function(){
remove_action( 'wp_footer', array( UM()->modal(), 'load_modal_content'
});
And if you don’t want to display this um_view_photo template for non-logged-in user, just use the following:
add_action("template_redirect", function(){
if( ! is_user_logged_in() ){
remove_action( 'wp_footer', array( UM()->modal(), 'load_modal_content' ), 9 );
}
});
Regards,
Great.
Thanks for the snippet to remove actions for modal, however I would prefer to solve the error rather than just hide it for logged out users.
I tried to copy and paste the file, to /wp-content/themes/milyin/ultimate-member/templates/ and changes made weren’t shown on frontend.
I tried to copy and paste the file to /wp-content/themes/milyin/ultimate-member/templates/modal/ changes made there weren’t shown either.
Please inform me the correct directory,
Also suggest the changes that need to be made to the template to achieve the desired results in Lighthouse.
Thanks in Advance
Hi @adityamilyin
You need to include a copy of the template file that has changes to match your desired result. You will need to customize it on your end.
Just include the template like this( it depends where you locate the copy of the template ):
add_action( 'wp_footer', function(){
include_once "path/wp-content/themes/your-theme/ultimate-member/modal/um_view_photo.php"
});
Regards,
Hi @adityamilyin
Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. 🙂
Regards,
Viewing 5 replies — 1 through 5 (of 5 total)