Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

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

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Do you want to make your page or post titles link to external links in WordPress?

Maybe you want to redirect users from your WordPress site to an external website or page when they click on a post title. This could be useful if you are using your website as a hub to direct traffic to other content.

While WordPress doesn’t allow this by default, some of our WPBeginner readers have requested a solution, and we’ve come up with a couple for you.

In this article, we will show you how to link to external links from the post or page title in WordPress.

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

When Do You Need to Add Links in the WordPress Post Title?

There are several situations where linking your WordPress post, page, or custom post type title to a custom URL comes in handy.

Let’s say you offer ad space on your WordPress site that resembles a regular post. The title can link to the advertiser’s website instead of your own content, creating a clear path for users.

Or maybe you run a news aggregator website featuring both your own content and curated articles from other sources. Ideally, your homepage’s news section would automatically link the article titles to the right destination, whether that’s on your own site or an external one.

Alternatively, perhaps your homepage showcases products, but clicking them leads to individual product pages. You might prefer to link the titles directly to the category’s product catalog page for a broader overview.

With all that in mind, let’s go over how to link post titles in your WordPress website to external URLs. You can use these quick links to navigate through the tutorial:

This method is perfect for beginners or anyone who wants a simple solution to link their post or page title to an external URL.

Plus, this method is a great option if you want the title to link to custom URLs across your entire website.

First, you’ll need to install the Page Links To plugin. We have a helpful guide on how to install a WordPress plugin if you need a step-by-step walkthrough.

Once the plugin is installed and activated, open up a new post, page, or custom post type or edit an existing one using the block editor. You’ll now see a new tab called ‘Page Links To’ in the Post Settings sidebar.

Here, you’ll see two options: ‘Its normal WordPress URL’ (the default) and ‘A custom URL.’ Since we want to link to an external site, choose ‘A custom URL.’

Using the Page Links To plugin in the block editor

Now, simply paste the full external URL (including the https://) into the ‘Links To’ field. For example, if you were linking to the WPForms website, then you would enter ‘https://wpforms.com.’

There’s also a checkbox for ‘Open in new tab’ if you want visitors to the external site to keep your page open in the original tab when they click the title. Tick that box if needed.

Finally, click ‘Update’ or ‘Publish’ to save your changes.

If you go to your WordPress blog page, homepage, archive page, or anywhere else that your post or page title is displayed as an excerpt, you can try hovering over the title.

You will see that it now links to the external URL you specified.

Successfully adding an external link to a post title using the Page Links To plugin

Method 2: Using Custom Code (More Control)

This method is ideal for users comfortable with code and people who want more control over which pages their post titles link to a different URL.

For example, you may want the post title to link to an external URL if it’s viewed in the single post template but not when it appears on the homepage or archive pages.

To make things safe, we will use WPCode instead of editing theme files directly. This plugin makes it secure to insert custom code into WordPress, as it can prevent you from breaking your website if there are errors in the code.

You can check out our WPCode plugin review to learn more about it.

Step 1: Install and Set Up WPCode

First, you need to install and activate the WPCode plugin. We have a guide on how to install a WordPress plugin if you need help with that.

Once activated, navigate to Code Snippets » + Add Snippet. Here, choose ‘Add Your Custom Code (New Snippet)’ and click the ‘Use snippet’ button.

Adding custom code in WPCode

Next, change the ‘Code Type’ from HTML Snippet to ‘PHP Snippet.’

Give your snippet a clear name, like ‘External Links from Post Titles,’ so that you can easily identify it later on.

Creating a new WPCode code snippet for linking to external links from post titles

Now, choose one of the following code snippets:

Option 1: Make All Post Titles Link to External URLs

This code snippet will modify the URL of your post titles across various locations on your site, including single posts, the homepage, and archive pages.

The code checks if it’s a single post page, homepage, front page, or archive page. If it is, and you’ve set a custom URL using the steps mentioned later, the code will use that URL instead of the default permalink.

We will add a custom field named ‘custom_url’ in the block editor in the next step to specify the external URL for each post.

// Change post title URL for single post pages and homepage/front page
add_filter('post_link', 'check_for_custom_url', 10, 3);
function check_for_custom_url($permalink, $post, $leavename) {
$custom = false;
// Check if it's a single post page
if (is_single()) {
$custom = get_post_meta($post->ID, 'custom_url', true);
}
// Check if it's the homepage, front page, or archive pages
elseif (is_home() || is_front_page() || is_category() || is_tag() || is_archive()) {
$custom = get_post_meta($post->ID, 'custom_url', true);
}
// Return the custom URL if set, otherwise return the default permalink
return ($custom) ? esc_url($custom) : $permalink;
}

Let’s say you only want this code to run on the front page but not on the archive pages.

Then, you can just remove the code that says is_category(), is_tag(), or is_archive(), like so:

// Change post title URL for single post pages and homepage/front page
add_filter('post_link', 'check_for_custom_url', 10, 3);
function check_for_custom_url($permalink, $post, $leavename) {
$custom = false;
// Check if it's a single post page
if (is_single()) {
$custom = get_post_meta($post->ID, 'custom_url', true);
}
// Check if it's the homepage, front page, or archive pages
elseif (is_home() || is_front_page()) {
$custom = get_post_meta($post->ID, 'custom_url', true);
}
// Return the custom URL if set, otherwise return the default permalink
return ($custom) ? esc_url($custom) : $permalink;
}

Option 2: Make Post Titles in Single Post Templates Link to External URLs

This code is useful if you want only the post title in the single post template to link to external URLs, not the ones on other pages like the homepage, archive pages, and so on.

This way, the user can still visit the blog post and read it, but they can also click on the post title to check out another resource.

An example of this is a podcast website. You might use your site to publish the summaries or transcripts of the episodes but host the audio on Spotify. With this method, you can publish your podcast episodes on your site but direct people to Spotify when they click on the post title.

The code below checks if the current request is for a single post. If it is, and you’ve set a custom URL using the custom field, it will use that URL in the post title:

// Hook into the 'post_link' filter to modify the permalink of a post.
add_filter('post_link', 'check_for_custom_url', 10, 3);
// Define the callback function for the 'post_link' filter.
function check_for_custom_url($permalink, $post, $leavename) {
// Check if the current request is for a single post.
if (is_single()) {
// Retrieve the value of the 'custom_url' custom field for the current post.
$custom = get_post_meta($post->ID, 'custom_url', true);
// If the custom field has a value, use it as the permalink. Otherwise, use the default permalink.
return ($custom) ? esc_url($custom) : $permalink;
} else {
// If the current request is not for a single post, return the default permalink.
return $permalink;
}
}

Once you’ve pasted the code snippet, scroll down to the ‘Insertion’ section. Make sure the Insert Method is set to ‘Auto Insert’ and the Location is set to ‘Run Everywhere.’

Finally, activate the snippet using the toggle and click ‘Save Snippet.’

Choosing the insertion method and location in WPCode

Step 2: Enable Linking in Titles (Block Theme Users Only)

If you are using a block theme, there’s an extra step you should do to ensure the code works.

First, go to Appearance » Editor to open the Full Site Editor.

Selecting the Full-Site Editor from the WordPress admin panel

You will now see some options to edit your block theme.

Go ahead and click on ‘Templates.’

Opening the Templates menu in full-site editor

At this stage, locate the ‘Single Posts’ template.

Once you’ve found it, click on it.

Opening the Single Posts template in the full-site editor

Now, click the pencil ‘Edit’ icon.

This will open the block editor.

Editing the Single Posts template in the full-site editor

Once inside the editor, click on the ‘Title’ block.

In the Block Settings sidebar, enable the ‘Make title a link’ option and the optional ‘Open in new tab’ option. Leave the ‘Link Rel’ field empty.

After that, click ‘Save.’

Enabling linking in post titles in the block editor

Step 3: Add a New Custom Field

Now, let’s add the ‘custom_url’ custom field in the block editor.

Inside the editor, click the three-dot menu in the top right corner of the block editor and select ‘Preferences.’

Opening the Preferences menu in the block editor

Go ahead and navigate to the ‘General’ tab.

After that, scroll down to ‘Custom fields.’ Enable it and refresh your page by clicking ‘Show & Reload Page.’

Enabling custom fields in the block editor

A new custom field section will appear.

You need to click ‘Enter New’ there.

Creating a new custom field in the block editor

In the ‘Add New Custom Fields’ section, enter ‘custom_url’ or whatever custom field you specified in the code earlier in the Label field.

In the ‘Value’ field, paste the external URL you want to link to. Once done, just click ‘Add Custom Field.’

Adding a new custom field in the block editor

Next, simply click ‘Update’ or ‘Publish’ to make your changes live.

Finally, visit your website to see if the code works. You can hover over your post title or use the Inspect tool to check.

Here’s what the post title’s URL should look like if you use the code from option 2:

An example of an external link successfully added to post titles with WPCode

Will Adding External Links in Post Titles Affect SEO?

Adding external links directly in your post titles has minimal impact on search engine optimization (SEO).

However, there are a few things to consider. When you link out to another website, you are essentially telling search engines that the other site might be a good source of information. Some of your “link juice” might pass to the external site, but it’s generally a small amount.

That said, if your titles contain many external links, they might confuse users or make them think they are leaving your site immediately.

If you still want to use external links in titles, then we recommend only linking out when the external site truly adds value to your content and is high-quality and highly relevant to your audience.

You can also add the ‘nofollow’ attribute to your external links in the title code. This tells search engines not to follow those links for ranking purposes.

On the other hand, if you’re reading this tutorial to direct users from your old website to your new one, you might want to consider using redirects instead.

Redirects tell search engines (and users) that a particular page has permanently moved to a new location. This can be beneficial for WordPress SEO because the link juice from your original page will transfer to the new location.

All in One SEO (AIOSEO) is a WordPress plugin that can help you do just that. Its user-friendly interface makes it easy to set up redirects for specific posts or pages. No code is required, making this plugin beginner-friendly.

All in One SEO Redirects Tab

You can learn more about the topic in our beginner’s guide to setting up 301 redirects.

We hope this article helped you learn how to link to external links from the post title in WordPress. You may also want to check out our ultimate guide to internal linking and our expert pick of must-have WordPress plugins to grow your website.

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

23 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. 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?

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

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

  5. Sing says

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

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

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

  8. martin says

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

    Best from Italy,

    Martin

  9. 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”

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

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

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

Leave A 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.