How to Link WordPress Post Title to an External URL?

Do you want to link WordPress post titles to an external URL? Look no further; you have come to the right place. We will show you the easiest ways to handle this issue. Introduction Sometimes, you will need to link…

How to Link Wordpress Post Title to an External URL?

Do you want to link WordPress post titles to an external URL? Look no further; you have come to the right place. We will show you the easiest ways to handle this issue.

Introduction

Sometimes, you will need to link your WordPress post title to external resources for various reasons. For example, you can share a link with your readers instead of creating a whole post.

Moreover, adding an external link from the WordPress post title also allows your visitors to simply visit your website by clicking on your post/page. This way, you can save a lot of time building a post or generating navigation elements.

For this reason, in today’s blog, we will teach you how to quickly link WordPress post titles to an external URL. Now, let’s go over the following sections.

How to link WordPress post titles to an external URL?

Method 1: Using the Page Links To plugin

Page Links To plugin is a useful tool that allows you to make a WordPress post/page or custom post type link to a URL that you provide instead of its WordPress URL.

Before using this plugin, you need to install it.

Just go to Plugins > Add New from your WordPress dashboard menu. Then you can use the search bar to look for the “Page Links to” plugin. After that, simply click on the “Install Now” button and “Activate” it.

Link WordPress post title

Once the plugin has been installed, edit any existing post or start creating a new one.

In the post editor, scroll down and you will see the new “Page Links To” meta box.

Link WordPress post title

Let’s select the ” A custom URL” option and enter the URL that you want to link the post title to.

After that, don’t forget to click on the Publish/Update button to save your post.

Now, your post title will link to the custom URL that you provided.

Method 2: Using code snippets

This method doesn’t require you to install any additional plugin. However, you have to add code snippets to your WordPress site.

Simply add the following 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 will help you find a custom field that contains your custom URL. If the post has the custom field, it outputs the post title linked to your URL.

Next, you need to replace your theme’s default display of the post title with this function. You can look for it in archives.php, content.php, category.php, and other templates. It will be similar to the following code.

<?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>

Now, it is time to replace it with the code snippets below:

<?php print_post_title() ?>

In the next step, you need to add the external URL to the post. Similarly, you can edit any existing post or click on the “Add New” button to create a new one.

On the post editor screen, let’s find the “custom fields” meta box.

If the custom fields meta box is not available below the editor area, you need to click on the “Screen Options” in the top right corner of the screen. This will expand the menu with a list of options. You need to tick the checkbox next to the “Custom Fields” option.

Link WordPress post title

After that, you can find the “Custom fields” meta box displayed below the post editor. Let’s click on “Enter New“.

link wordpress post title to external url 4 1

Then, under the “Name” field, you need to enter external_url and the URL you want to add to the post title in the “Value” field.

link wordpress post title to external url 5

Now, you can Publish or Update your post. Your post title will be linked to the URL that you entered in the custom field.

Next time you need to add a link, simply select the external_url custom field from the drop-down menu. Then provide your external link in the “Value” field.

Final thoughts

All the methods we have just shown are easy to use and effective. Hopefully, this article can help you easily link WordPress post title to an external URL. If you have any questions or queries, let us know by leaving a comment below.

Furthermore, you can drop by our free WordPress Themes website to explore many gorgeous, modern themes and templates. If you want to build a professional website, don’t miss our website.

Build it with a template

Start from a finished design: Joomla templates, WordPress themes or the AI-ready block themes. Every template has a free version and a live demo.

Stuck on a template?

Pro customers can open a ticket; everyone can read the documentation.

Free download

We'll send the link, setup tips and update notices, and you can reach us anytime through our AI assistant and contact form.

The download starts at once. We email you the link and ask you to confirm your address. Privacy policy.