Trailing slash
-
Hello.
WordPress 5.6.2
YoastSEO 15.9.1My old theme had in-build feature to add slash to the end of category URL (like https://site_host/category_name/). I used Yoast SEO with it and everything was ok. Until I installed new modern theme.
This theme doesn’t have feature with slash. No problem, I manually corrected URLs. I used this code:
function pcl_smart_trailingslashit($string) { // Ensure, that there is one trailing slash. $string = rtrim($string, '/') . '/'; // If there is a filename extension like .html or .php, then remove the trailing slash. if ( 0 < preg_match("#\.[^/]+/$#", $string) ) { $string = rtrim($string, '/'); } return $string; } add_filter('user_trailingslashit', 'pcl_smart_trailingslashit');
A few days later I found out, that all category URL in Google now looks like https://site_host/category_name The investigation revealed, that Yoast SEO made all links in page header without slash. Pffff… ??
I corrected ‘link rel=”canonical”‘ and ‘meta property=”og:url”‘. Same code with wpseo_canonical and wpseo_opengraph_url filters.
But there is block ‘script type=”application/ld+json”‘ with a lot of urls. And maybe some other blocks, which I have not found yet.
Is it possible to correct URLs and add trailing slash for all Yoast SEO blocks at once? How? If not possible, what filter (or what else) should I use for correcting block ‘script type=”application/ld+json”‘?
- The topic ‘Trailing slash’ is closed to new replies.