Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

canonical-presenter hook removes final slash in URL if URL contains a period #21371

Open
2 of 11 tasks
MatthewSbar opened this issue May 7, 2024 · 1 comment
Open
2 of 11 tasks

Comments

@MatthewSbar
Copy link

MatthewSbar commented May 7, 2024

  • I've read and understood the contribution guidelines.
  • I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened

I have pages where I need to override the canonical - if I have a URL without any periods whatsoever, everything works fine, but if my URL includes a period, the final slash in the URL gets removed for some reason

To Reproduce

Step-by-step reproduction instructions

Add a filter like so (assuming the site is https://www.yubico.com)

function yubicool_wwyk_canonical($canonical) {
    $canonical = home_url('/works-with-yubikey/catalog/relate.it/');
    echo $canonical; // This prints https://www.yubico.com/works-with-yubikey/catalog/relate.it/
    return $canonical; // The canonical is set to https://www.yubico.com/works-with-yubikey/catalog/relate.it <- No trailing slash
}
add_filter('wpseo_canonical', 'yubicool_wwyk_canonical');
  1. Check the canonical URL of the page

Expected results

  1. The echoed URL is equivalent to the canonical URL

Actual results

  1. The canonical URL is missing a trailing slash

Screenshots, screen recording, code snippet

If possible, please provide a screenshot, a screen recording or a code snippet which demonstrates the bug.

Technical info

  • If relevant, which editor is affected (or editors):
  • Block Editor
  • Gutenberg Editor
  • Elementor Editor
  • Classic Editor
  • Other:
  • Which browser is affected (or browsers):
  • Chrome
  • Firefox
  • Safari
  • Other:

Used versions

  • Device you are using: (docker) ubuntu:focal
  • Operating system: ubuntu:focal
  • PHP version: 7.4
  • WordPress version: 7.4
  • WordPress Theme: 5.6.3
  • Yoast SEO version: 22.6
  • Relevant plugins in case of a bug:
@josevarghese
Copy link
Contributor

Hi @MatthewSbar

Thanks for using the Yoast SEO plugin and also for creating the issue. I tried to reproduce the issue by creating a URL with a period within the slug. Unfortunately, I noticed that WordPress is changing the period to - hypen automatically. So, is there any way to replicate this, as WordPress seems to be not allowing the period in the slug by default?

We look forward to hearing from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants