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.

Share:
Share on Facebook1Share on LinkedIn0Tweet about this on TwitterShare on Google+0Buffer this pageDigg thisShare on Reddit0

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. Required fields are marked *

Most Popular Posts

What is Press This in WordPress

Posted on 5 years ago

Bhumi

Overview of Views in MySQL

Posted on 6 months ago

Bhumi

How to Lock File in PHP

Posted on 5 years ago

Bhumi

Facade implementation in Laravel

Updated 3 weeks ago

Bhumi

MySQL coalesce() function

Updated 17 years ago

Bhumi

How to use JavaScript Promise API?

Updated 17 years ago

Bhumi

What are Lambdas and Closures in PHP?

Updated 17 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 3 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 4 years ago

Bhumi