• Resolved sharespring

    (@sharespring)


    I need a function to see where a URL would redirect to.

    Something like this pseudo-code:
    get_url_after_redirects('/some-old-slug') # Returns /the-new-slug

    I’ve looked and didn’t find a function that does this, but I hope that utilizing the power of Redirection, this can be done. Any ideas how to do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author John Godley

    (@johnny5)

    What are you trying to do? Such a function would only work for Redirection redirects, and not in general.

    Thread Starter sharespring

    (@sharespring)

    Yes, I understand that this would only be for Redirection. I can handle finding any other possible redirects, such as with the _wp_old_slug for posts.

    My use case is this:
    I’m dynamically adding some link rel="alternate" tags that contain the URL to the current page in different languages (multisite). If you’re on the US /contact page, it will show /kontakt for Germany. We use Redirection already on the German site to redirect from /contact to /kontakt. So, if there’s a way to run some function like get_url_after_redirects('/contact') then I would be able to get the final URL that it would reach after Redirection.

    Plugin Author John Godley

    (@johnny5)

    You could try Red_Item::get_for_url(). There is no guarantee this function won’t change.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Function to see where a URL would redirect to’ is closed to new replies.