Family Encyclopedia >> Electronics

How to link to external links from post title in WordPress

Do you want to add an external link as a post title in WordPress? Sometimes you may just want to share a link with your users. Instead of submitting 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.

How to link to external links from post title in WordPress

Method 1:Link Post Title to External Link in WordPress Using Plugin

This method is easier and is recommended for beginners.

The first thing you need to do is install and activate the Page Links to plugin. For more details, check out 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'll notice the new 'Page Links' meta box below the post editor.

How to link to external links from post title in WordPress

Click 'A Custom URL' to add the link you want to add to the post title. Now you can save or publish your post.

That is all. The post title will now link to the custom URL you provided.

It is not necessary to use it only for external links. You can also use it to send users to different posts and pages on your WordPress site.

Method 2:Add an external link to the post title using the code

This method requires you to add code to your WordPress site. You can use this method if you feel comfortable pasting web snippets 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 (vacío ($ post_val)) $ link = $ perm; else $ link = $ post_val [0]; else else $ link = $ perm; eco '

'. $ título.'

';

This search code simply looks for a custom field that contains your custom URL. If the post has the custom field, it generates the post title linked to its URL.

The next step is to replace the default display of your theme's post title with this feature. You'll find it in archives.php, content.php, category.php and other templates. It would look something like this:

 ', esc_url (get_permalink ())),''); ?> 

You need to replace it with this code:

 

The code part is done, 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 can't see the custom fields meta box, you need to click Screen Options in the top right corner of the screen. This will bring up a menu where you need to check the box next to 'Custom Fields'.

How to link to external links from post title in WordPress

You'll find the custom fields metadata box below the post editor.

Click 'Enter New' and then enter external_url in the 'Name' field and the URL you want to add to the post title in the 'Value' countryside.

How to link to external links from post title in WordPress

Now you can save or publish your post. That's it, your post title will now link to the URL you added in the custom field.

The next time you need to add a link, just select external_url custom field from the dropdown 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 to your WordPress site.

If you enjoyed this article, please subscribe to our WordPress YouTube Channel video tutorials. You can also find us on Twitter and Facebook.