preloader LOADING

42Works Blog

Posted on April 2, 2020

WordPress 101: Tips, Tricks & Hacks (How To Link External Links From Post Titles)

WordPress has made blogging on the internet extremely simple for newbie bloggers. But just because WordPress as a Content Management System has blogging simple, doesn’t mean it’s easy. Creating quality content and building a readership is a tough task. Today if you want to build your successful blog, you need to entice your reader with more. 

How you may be able to do that? The answer is simple enough, share quality content that others create. This will not only create a lot of goodwill within your niche, but it will also help in building your brand as an authoritative blog. You can share external content links on your WordPress website title posts. This will help you and your reader to be open to new content and fresh content.  

Link External Links From Post Titles

So do you want to add external content links from your post titles, but don’t know how to add them? Well, don’t worry we have a hack tailor-made for your needs. The below points elaborate on the steps of the hack: 

Step 1 – Add the following code snippet to functions.php file.

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=='url1' || $pkey=='title_url' || $pkey=='url_title') {

$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>';

}

Step 2 – After adding the above snippet, open your index.php file and find the blow code:

<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>

Step 3 – Once you find above code snippet, replace it with the code below: 

<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php print_post_title() ?></a></h2>

Step 4 – Save changes made to both the .php files and now voila!


Leave a Comment:

Your email address will not be published.

para glider
Have a Project ?
We are just as excited

Contact Us

about your Idea
My name is
& I'm interested in discussing about
for my project
. You can email me at
or ring me up at
.

Virginia United States 18.206.13.28 https://42works.net/tech-hacks/link-external-links-from-post-titles-in-wordpress