Category links in menu with regional filter increase Google soft 404
This topic contains 5 replies, has 3 voices, and was last updated by Marc Mathys 7 years, 2 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
February 20, 2017 at 1:58 pm #362667
Hi,
Since I’ve added all the categories to my menu, I get these email alerts from google telling me I have hundreds of “soft 404” errors. I tracked it back to the categories in my menu. If I have only one listing in a town that has one category, all other categories for all CPT’s in the menu will yield to a “soft 404” (as google calls it) because there’s not going to be any result.
Is it possible to remove the automatic location part of the URL from those categories?
Here’s an example: https://www.arbolife.com/stores/switzerland/neuchatel/saint-aubin-sauges/locaze/ This is the only store in this village. Anything clicked from the categories menu (other than online shops) will provide an empty search result.
Best,
MarcFebruary 20, 2017 at 10:26 pm #362748Hi Marc,
the only way to do that is to add them as custom links.
Example:
https://www.arbolife.com/stores/
https://www.arbolife.com/stores/health-food/GeoDirectory will not add the location to custom links.
Thanks
February 20, 2017 at 11:23 pm #362762Hi Paolo,
I understand this would work. I might prefer customising to avoid hardcoding all the links into menu.
Could you please point to the function or file in the GD plugin that creates those links?Thanks,
MarcFebruary 20, 2017 at 11:26 pm #362764I don’t think there is a hook that will allow you to customize this without losing the mod after every update.
However I asked to the developers to let you know.
Thanks
February 21, 2017 at 12:23 pm #362820I think the hook you are looking for is:
add_filter('term_link', 'geodir_get_term_link', 10, 3);
You would have to remove it before the menu is built and then add it back after
remove_filter('term_link', 'geodir_get_term_link', 10); // build menu add_filter('term_link', 'geodir_get_term_link', 10, 3);
Stiofan
February 22, 2017 at 9:14 am #363089Hi Stiofan,
Thanks, it works like a charm. Here’s the code if someone wants to do the same thing:
/************************************************************************** * Remove the geodir_get_term_link Filter for building the Kleo menu * (this removes the location part of the link in all categories in the menu) **************************************************************************/ // Removing the filter also removes WPML slug translation. We need to create a new filter only for this. // Content of this function is inspired by geodir_term_link() in taxonomy_functions.php, line 1695 // (Note this function and it's usage can be removed if not using WPML) function custom_geodir_translate_term_link($termlink, $term, $taxonomy) { $geodir_taxonomies = geodir_get_taxonomies('', true); if (isset($taxonomy) && !empty($geodir_taxonomies) && in_array($taxonomy, $geodir_taxonomies)) { // Alter the CPT slug if WPML is set to do so if (function_exists('icl_object_id')) { $post_types = get_option('geodir_post_types'); $post_type = str_replace("category","",$taxonomy); $post_type = str_replace("_tags","",$post_type); $slug = $post_types[$post_type]['rewrite']['slug']; if (gd_wpml_slug_translation_turned_on($post_type)) { global $sitepress; $default_lang = $sitepress->get_default_language(); $language_code = gd_wpml_get_lang_from_url($termlink); if (!$language_code ) { $language_code = $default_lang; } $org_slug = $slug; $slug = apply_filters('wpml_translate_single_string', $slug, 'WordPress', 'URL slug: ' . $slug, $language_code); if (!$slug) { $slug = $org_slug; } $termlink = trailingslashit(preg_replace("/" . preg_quote($org_slug, "/") . "/", $slug ,$termlink, 1)); } } } return $termlink; } // Remove the geodir_get_term_link and add the custom filter before menu is built (after body tag) function remove_gd_term_link_filter() { remove_filter('term_link', 'geodir_get_term_link', 10); add_filter('term_link', 'custom_geodir_translate_term_link',10, 3); //delete this if not using WPML } add_action('kleo_after_body', 'remove_gd_term_link_filter'); // Remove the custom filter and add back the geodir_get_term_link filter before the main content function add_gd_term_link_filter() { remove_filter('term_link', 'custom_geodir_translate_term_link', 10); //delete this if not using WPML add_filter('term_link', 'geodir_get_term_link', 10, 3); } add_action('kleo_before_main', 'add_gd_term_link_filter');
Cheers,
Marc -
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket