Jackson
Forum Replies Created
-
@jdembowski I’ve now thoroughly exhausted all options with Yoast, Elegant Themes, and the Google Webmasters Forum. They all point to it being a WordPress issue.
None of them understand why these /?cat=-1 pages are being created and showing up in Google search results.
We switched to the default WordPress theme and the issue still persists there, so that ruled out it being the Divi theme.
They are all pointing me back to WordPress to find a solution. They have all advised that if WordPress won’t help with the issue then I could try to cheat the system and inject some code as suggested below with one of these two options:
1. From Google Webmasters Forum – “Fix the ‘negative’ category URL, and it will fix all the pages at once:
Looking a bit more, seem the correct way to triger 404, is like
https://stackoverflow.com/questions/13125169/wordpress-trigger-404<?php
if (isset($_GET[‘cat’]) && $_GET[‘cat’] == -1) {
status_header(404);
include( get_404_template() );
exit;
}If was my site I would just stick that at the top of index.php. But maybe it would be more correct to put in in the themes functions.php file?”
2. From Elegant Themes – “I am not sure how Yoast works exactly and if it’s adding tags to the head section however you can try this PHP code and place it to the functions.php of your child theme and check the results on Google
function no_index_archive() {
if (is_archive()) {
echo ‘<meta name=”robots” content=”noindex”/>’;
}
}
add_action(‘wp_head’,’no_index_archive’);If it won’t help I would suggest to check with Yoast support again and let them know that issue exist in default WordPress theme too.”
Please let me know what you make of this. Thank you!
Jackson
=D
Here’s what Google is telling me…
“Would agree that setting some sort of redirect on the URL would be good. Its clearly some sort of ‘mistake’ page. Looks like the ‘cat=’ forwards it to category listing page handler. but -1 is not a real category. So its then probably just trying to list all posts. That particular post is the most recent post, but because it not really a ‘category’ page, it rendered by normal page handler, whch ends up putting in canonical etc. Although perhaps even better would be to ‘fix’ wordpress, so this URL doesnt return content. A the most crude… <?php if (isset($_GET[‘cat’]) && $_GET[‘cat’] == -1) { header(‘HTTP/1.0 404 Not Found’); exit;}
Or even better would be just the fix the code, as it clearly knows when a category doesnt existhttps://www.aframeforward.com/?cat=1232423523it should do exactly the same for -1In fact it seems does the same for anything <1, eg /?cat=-1232423523 gives the same duplicate.
Possibly do something better than return no content, so that if users end up there it ok. But important is not to return the content of an actual page. This is better than trying to ‘noindex’ the page, as it risks affecting real pages.”
and…
“Just for reference, I dug a bit in wordpress source. Seems it tries to support negative cat ids, to function as exclude filter $cat_array = preg_split(‘/[,\s]+/’, $q[‘cat’]);
$q[‘cat’] = ”;
$req_cats = array();
foreach ( (array) $cat_array as $cat ) {
$cat = intval($cat);
$req_cats[] = $cat;
$in = ($cat > 0);
$cat = abs($cat);
if ( $in ) {
$q[‘category__in’][] = $cat;
$q[‘category__in’] = array_merge( $q[‘category__in’], get_term_children($cat, ‘category’) );
} else {
$q[‘category__not_in’][] = $cat;
$q[‘category__not_in’] = array_merge( $q[‘category__not_in’], get_term_children($cat, ‘category’) );
}
}
This is from wp-includes/query.php So that is what is being ‘shown’. All posts NOT in category 1! I would guess this is such little known functionality, that your theme, and perhaps even Yoast, is not ‘seeing’ it as a real category page. Hence yoast does not inject the noindex tag, and the rel=canonical is being created incorrectly. (don’t have Yoast installed to check it source)”What do you make of this?
Thanks!
Jackson
=D
Thanks for the response Jan.
Yoast told me it was a theme (Divi) issue.
Divi (Elegant Themes) told me it was a WordPress pagination issue.
I’ll post in Google and keep my fingers crossed. 🤞