Do you want to add an external link as post title in WordPress? Sometimes you may just want to share a link with your users. Instead of sending them to a post, you may want the post title to link to the other website. In this article, we will show you how to link to external links from the post title in WordPress.
Method 1: Linking Post Title to an External Link in WordPress using Plugin
This method is easier and is recommended for beginners.
First thing you need to do is install and activate the Page Links To plugin. For more details, see our step by step guide on how to install a WordPress plugin.
Upon activation, simply create a new post or edit an existing one. You will notice the new ‘Page Links To’ meta box below the post editor.
Click on ‘A custom URL’ to add the link you want to add to post title. Now you can save or publish your post.
That’s all. The post title will now link to the custom URL you provided.
It is not necessary to use it for external links only. You can also use it to send users to different posts and pages on your WordPress site.
Method 2: Add External Link to Post Title Using Code
This method requires you to add code to your WordPress site. You can use this method if you are comfortable with pasting snippets from web into WordPress.
Simply add this code to your theme’s functions.php file or a site-specific plugin.
function print_post_title() { global $post; $thePostID = $post->ID; $post_id = get_post($thePostID); $title = $post_id->post_title; $perm = get_permalink($post_id); $post_keys = array(); $post_val = array(); $post_keys = get_post_custom_keys($thePostID); if (!empty($post_keys)) { foreach ($post_keys as $pkey) { if ($pkey=='external_url') { $post_val = get_post_custom_values($pkey); } } if (empty($post_val)) { $link = $perm; } else { $link = $post_val[0]; } } else { $link = $perm; } echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>'; }
This code looks simply looks for a custom field containing your custom URL. If the post has the custom field, then it outputs the post title linked to your URL.
The next step is to replace your theme’s default display of post title with this function. You will find it in archives.php, content.php, category.php and other templates. It would look something like this:
<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
You need to replace it with this code:
<?php print_post_title() ?>
The code part is over, now you need to add the external URL to the post. Simply edit the post or create a new one. On the post editor page, look for the custom fields meta box.
If you cannot see the custom fields meta box, then you need to click Screen Options in the top right corner of the screen. This will bring down a menu where you need to check the box next to ‘Custom Fields’.
You will find the custom fields meta box below the post editor.
Click on ‘Enter New’ and then enter external_url
in the ‘Name’ field and the URL you want to add to post title in the ‘Value’ field.
You can now save or publish your post. That’s all, your post title will now be linked to the URL you added in the custom field.
Next time you need to add a link, you just need to select the external_url
custom field from the drop down menu and enter your external link in the value field.
We hope this article helped you learn how to link to external links from the post title in WordPress. You may also want to see our guide on how to add an external link icon on your WordPress Site.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
John says
Will this work on images relating to the post titles as well? So clicking on either image or post title takes you to the page on the external site?
WPBeginner Support says
The plugin would do that for your featured image if that is what you mean.
Admin
Alessandro says
is there a way to link post titles to custom links, but only if they are present in one page (so not for the whole site)?
Example: search results page of plugins like search & filter or toolset
WPBeginner Support says
We do not have a recommended method for setting that up at the moment.
Admin
Kam says
Thank you. This is really helpful. Would this plugin work for automated RSS feeds? i.e. for aggregator sites? I’m assuming no, as the titles are constantly changing. I’m trying to take the user to the original source with one click on the title.
WPBeginner Support says
You would want to reach out to the support for the aggregator tool you are using for the options you have available.
Admin
Sing says
Is the above method and Content syndication are one and the same? Or both are different topic.
WPBeginner Support says
That is a different topic
Admin
Maksym says
Amazing! This is what I was looking for. Thank you so much
WPBeginner Support says
Glad our article was helpful
Admin
mostafa says
Thank you for this tutorial. It helped me a lot but how to use this for cpt (in my case a testimonial) and open the link in a new tab . Thank you.
WPBeginner Support says
You’re welcome
Admin
Brandon H. says
You saved my website! Thank you so much!!
mehmet says
Thank you for useful information.
My English is a little bad.
I want to use this kind of plugin on my site
But the bold type in the text will be automatically linked to the text.
Links to other posts within the site
Is there such an extension?
martin says
Thanks for that, pretty helpful. Found a lot of help on this site already!
Best from Italy,
Martin
Tammy says
Is there a way to require the external url to be unique? I’m using wp-directory and would love to be able to make this custom field “unique required”
Melch Wanga says
Its a good post indeed. In response to Toni, in my case I am developing a website for film production company and I have “Equipment Hire” as a services in ‘service’ custom post type. Equipment Hire is quite huge and I am using WooCommerce to add the various equipment hence I have Shop page that lists all the equipment available for hire. The trick is to ensure that whenever a user clicks on “Equipment Hire” service, they are directed to the Page set as the Shop page instead of the default Equipment Hire single post page.
Mel says
Hi, how is this going to affect SEO? Can we add rel=”nofollow” to an external link?
Thanks
Ariel says
great post!
Palashtd says
Recently I have started blogging.
I could think how to add External Links from the Post Title. But finally I got an awesome tip from this post. I have tested by following this tutorial. I am happy to get these tips because it’s working for me.
Thanks for sharing this information.
Toni Weidman says
I’m not sure why you would want to do this. Can you clarify what the purpose of this process is. Thank you.