Back to Top

How to use an external URL in WordPress?

HOW TO USE AN EXTERNAL URL IN WORDPRESS

After a long I get time to post because of very busy schedule.Today I arranged some time and come with something new. In this article, I am going to explain how you can use external URL in WordPress and redirect to that URL when clicking on post/link.

Recently, I was working on one theme and in that I am importing posts from other sites and want to redirect to actual /origin site if click on title or link found in google.

So, Let’s understand how I have done it. I have stored external URL/link as guid into the post in WordPress and permalink will be a URL of our site.So, we need to rewrite and redirect to URL and need to change the permalink.

Well, following filter hook is used to replace permalink with guid, if post’s guid is different than the site’s base URL. Here, I can get Host URL by parse_url function.

Next, action hook is used for redirecting template means if permalink of the own site found in somewhere or in the search engine, We also need to redirect to external/ original URL.Here, I have used the same condition like above just changes code of redirection.

That’s it. Place above code into your theme’s function.php file and run the code into browser :).

Recommended Read:

WordPress Action Hook
Auto-tagging in WordPress
To get Last auto increment id in WordPress

Hope this helps someone else out.As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Comments (1)

  1. faten sultan says:

    thanks for the code
    i am searching on the opposite side
    i have working non-wordpress site
    and i am transferring now to wordpress and i want my old links url (5400 link) to be the same as old
    i know solution is 301 redirection but actually i don’t think i can do that , as my url’s are complected
    is there any other way to do that???

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

Newly Approved Joomla Module

Posted on 10 years ago

Bhumi