WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How to Link to External Links from the Post Title in WordPress

How to Link to External Links from the Post Title in WordPress

Last updated on June 20th, 2016 by Editorial Staff
218 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Link to External Links from the Post Title in WordPress

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.

Adding External Link to WordPress Post Title

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.

Adding a custom URL in page links to

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’.

Show custom fields meta box on the post edit screen in WordPress

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.

Adding new custom key

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.

218 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • Google Analytics in WordPress

    How to Install Google Analytics in WordPress for Beginners

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

21 Comments

Leave a Reply
  1. John says:
    Oct 16, 2020 at 4:23 pm

    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?

    Reply
    • WPBeginner Support says:
      Oct 19, 2020 at 9:55 am

      The plugin would do that for your featured image if that is what you mean.

      Reply
  2. Alessandro says:
    Aug 29, 2020 at 2:44 am

    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

    Reply
    • WPBeginner Support says:
      Sep 1, 2020 at 9:42 am

      We do not have a recommended method for setting that up at the moment.

      Reply
  3. Kam says:
    Jun 6, 2020 at 7:26 pm

    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.

    Reply
    • WPBeginner Support says:
      Jun 8, 2020 at 3:59 pm

      You would want to reach out to the support for the aggregator tool you are using for the options you have available.

      Reply
  4. Sing says:
    Jun 5, 2020 at 1:32 am

    Is the above method and Content syndication are one and the same? Or both are different topic.

    Reply
    • WPBeginner Support says:
      Jun 5, 2020 at 9:05 am

      That is a different topic

      Reply
  5. Maksym says:
    Apr 8, 2020 at 3:25 pm

    Amazing! This is what I was looking for. Thank you so much

    Reply
    • WPBeginner Support says:
      Apr 9, 2020 at 8:59 am

      Glad our article was helpful :)

      Reply
  6. mostafa says:
    May 31, 2019 at 12:38 am

    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.

    Reply
    • WPBeginner Support says:
      May 31, 2019 at 10:27 am

      You’re welcome :)

      Reply
  7. Brandon H. says:
    Nov 20, 2018 at 2:14 pm

    You saved my website! Thank you so much!!

    Reply
  8. mehmet says:
    Nov 5, 2017 at 1:05 pm

    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?

    Reply
  9. martin says:
    Jul 18, 2017 at 4:27 am

    Thanks for that, pretty helpful. Found a lot of help on this site already!

    Best from Italy,

    Martin

    Reply
  10. Tammy says:
    May 18, 2017 at 9:13 am

    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”

    Reply
  11. Melch Wanga says:
    Jan 3, 2017 at 1:38 am

    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.

    Reply
  12. Mel says:
    Dec 17, 2016 at 11:57 pm

    Hi, how is this going to affect SEO? Can we add rel=”nofollow” to an external link?

    Thanks

    Reply
  13. Ariel says:
    Oct 6, 2016 at 4:57 am

    great post!

    Reply
  14. Palashtd says:
    Jun 21, 2016 at 11:25 am

    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.

    Reply
  15. Toni Weidman says:
    Jun 20, 2016 at 9:03 am

    I’m not sure why you would want to do this. Can you clarify what the purpose of this process is. Thank you.

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
All in One SEO
Improve website SEO rankings with AIOSEO plugin. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2021 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2021)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2021)
    • SiteGround Reviews from 4464 Users & Our Experts (2021)
    • Bluehost Review from Real Users + Performance Stats (2021)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2021 – Step by Step Guide
Deals & Coupons (view all)
LiveChat logo
LiveChat Inc Coupon
Get a 30 day free trial and 30% OFF LiveChat, one of the best live chat service providers for WordPress users.
LearnDash
LearnDash Coupon
Get the lowest price on the best learning management system (LMS) plugin for WordPress.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).

Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
  • Growth Fund
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon
  • AIOSEO

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress Security by Sucuri.