Did you see other sites link to external posts from their post title? Well that is because 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 are wasting your user’s time. This trick will allow you to link to external links from your post title in WordPress
First open your functions.php file and add the following codes in there:
Blogging is all about
sharing resources, and often it is the case where blogger wants to just link to an external resource because he/she finds it useful to their readers. The main problem they face is that they have to make a new post in order to just tell the readers to go to another site. We have a solution for this problem and that is through a custom field hack which allows the WordPress blogger to link to the external resources in their post title. So when their user clicks on the post title, it takes them to another article.
This tutorial can help creating a resource section on your blog if you want to link to external resources, and it is a doorway to a lot more customization in WordPress if thought out correctly.
First thing you need to do is open your functions.php which is found in your template folder where other files like single.php and page.php is located. Paste the following code:
01 | function print_post_title() { |
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 ); |
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 ); |
16 | if ( empty ( $post_val )) { |
24 | echo '<h2><a href="' . $link . '" rel="bookmark" title="' . $title . '">' . $title . '</a></h2>' ; |
These codes must be placed 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: