Entertainment | Relationships | Lifestyle | Health | Cars

Wednesday, 12 October 2016

How to Link to External Links from Your Post Title


Link to External Links from Your Post Title
In our today’s post we would be talking about how to link to an external blog from the post title. You may have seen it on other blogs and which to have the same feature on your wordpress blog. I love this feature because it helps to keep the long story short; instead of having to write a long article before linking out, you can simply link out with just a catchy post title.
This feature is very important for bloggers who have more than one blogs and which to link to their other blogs. This will definitely make your work easy.
It is completely useless to create a new post where inside you are going to tell users to go to another site to read it. You’ll be wasting your user’s time and yours too; you can use that time to make other productive posts. This trick will allow you to link to external links from your post title in WordPress.
You’ll first have to open your functions.php file and add the following codes in there:
01
function print_post_title() {
02
global $post;

03
$thePostID = $post->ID;
04
$post_id = get_post($thePostID);

05
$title = $post_id->post_title;
06
$perm = get_permalink($post_id);

07
$post_keys = array(); $post_val = array();
08
$post_keys = get_post_custom_keys($thePostID);

09

10
if (!empty($post_keys)) {

11
foreach ($post_keys as $pkey) {
12
if ($pkey=='url1' || $pkey=='title_url' || $pkey=='url_title') {

13
$post_val = get_post_custom_values($pkey);
14
}

15
}
16
if (empty($post_val)) {

17
$link = $perm;
18
} else {

19
$link = $post_val[0];
20
}

21
} else {
22
$link = $perm;

23
}
24
echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>';

25
}
Make sure you place the codes in php tags.
Then open your index.php and find the following code:
1
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
And replace it with:
1
<?php print_post_title(); ?>
This can also be accomplished by a use of a plugin called Page Links To.

No comments:

Post a Comment

Thanks for leaving a comment!