• Resolved Roman

    (@vladroman)


    Hello.

    WordPress 5.6.2
    YoastSEO 15.9.1

    My 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”‘?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @vladroman,

    Yoast SEO doesn’t control whether your pages have a trailing slash. It will use your site’s address and permalink settings for any URLs.

    It’s odd that you needed custom code to solve this problem. You should be able to control your WordPress site’s permalink settings under Settings > Permalinks without any need for custom code.

    Can you let us know if there is a trailing slash in the permalink settings and does adding a trailing slash there instead of using the custom code solve the problem?

    Thread Starter Roman

    (@vladroman)

    Permalinks in WordPress settings can be fixed for posts. For that site I have https://<host_name>/%category%/%postname%.html. Category prefix is empty (so default) and disabled in Yoast SEO settings (so don’t exist).

    Please, check, that I wrote about category (post list) URLs, not post. Post URLs is ok. I need to add trailing slash to category URLs.

    Plugin Support Michael Ti?a

    (@mikes41720)

    Hi,

    Can you please try resetting our indexables in the database tables by following the steps below?
    1. Install & activate the?Yoast Test Helper plugin
    2. Go to Tools > Yoast Test
    3. Locate the Yoast SEO section and click on the ‘Reset indexables tables & migrations’ button. Note: this won’t actually erase your SEO data, which is also stored in WordPress’ default tables. It’ll just reset our index (custom tables) for that data.
    4. Go to SEO > Tools, and under SEO data, click the “Start SEO data optimization” button to allow Yoast to rescan your?content.

    For your site’s health and safety, we recommend creating regular backups of your site and database. This is especially important before installing, updating, or removing plugins.

    Does this resolve the issue regarding the URLs not having a trailing slash for the schema data?

    Thread Starter Roman

    (@vladroman)

    Looks like resetting indexes solved problem with trailing slash in Yoast SEO output in page header. I even don’t need to use wpseo_canonical and wpseo_opengraph_url filters now. Hope, there won’t be any more surprises with changing canonical links and other metadata without me…

    Thank you for help.

    Plugin Support devnihil

    (@devnihil)

    @vladroman Thanks for confirming that this has corrected it. If you should need any further assistance, please do not hesitate to let us know.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Trailing slash’ is closed to new replies.