Subrata Sarkar

5 Cool WordPress Tricks that make your Blog more engaging

#1 Create Shortened URL

Why we need shortened URLs? Remeber, Twitter has become revolutionary and is a proven integral part of Social Media beside Facebook, LinkedIn and others. Twitter has a huge role in getting traffic from social media and hence sharing content in Twitter could never be kept aside!

Remember, Twitter has imposed a limit in the number of characters you can add to your post. In many cases, URLs are fairly large which prevents you adding enough additional text to tell users the story you want to share with them. This is a genuine problem!

Solution: Shortended URL technology takes you out of this bottleneck situation and create the room for you to breathe! To accomplish this, I am using tinyurl api for this reason. Just add the following lines in your theme’s funstions.php and enjoy the magic!

function getTinyUrl($url) {
    $tinyurl = file_get_contents("https://tinyurl.com/api-create.php?url=".$url);
    return $tinyurl;
}

Now, all you need to call this method in your single.php file and every post you have is now available with a shortened URL and ready to be Twitted!

<?php
$short_url = getTinyUrl( get_permalink( $post->ID ) );
echo '<a href="' . $short_url . '">' . $post->title . '</a>';
?>

#2 Make a room for Upcoming Posts

Having a list of upcoming posts turns a simple website into a more engaging one. By lisiting up the upcoming posts, you are actually making your audience aware about your next contents that are going to be available soon! And not only that, it is extremely helpful for a website to gain more RSS subscribers. This is fairly simple to integrate this.

There are two ways you can integrate this, by adding a function in your theme’s functions.php file and calling it whereever necessary, or by creating a Widget and placing in it sidebars. But I would go for widget, only if I have different areas on the websites dedicated for this.

I will stick to a simple function call in this article. To know about how to create a Widget in WordPress, refer to “How to Create a Widget in WordPress”.

<div id="upcoming_posts">
  <div id="upcoming_posts_header"><p>Coming Up...</p></div>
  <?php query_posts('showposts=10&post_status=future'); ?>
  <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div
      <p class="upcoming_posts_title"><b><?php the_title(); ?></b><?php edit_post_link('e',' (',')'); ?><br />
      <span class="datetime"><?php the_time('j. F Y'); ?></span></p>
    </div>
  <?php endwhile; ?>
  <?php endif; ?>
</div>

#3 Display Related Posts (Without a Plugin):

Having a list of related posts hugely boosts up the visitor engagement of your website. In this example, I will display a list of 5 published post titles related to the first tag on current post. By doing this, you are actually guiding your visitors effectively into more contents of your website.

Usually, this list should be displayed on post detail page (single.php in its simplest form). Let’s create a simple method for this in theme’s functions.php and call it on single.php. Please note, if you place the same code in your sinlge.php file, it will work exactly the same way, but I would recommend to keep functions in separate file.

function get_related_posts() {
     /* Lists 5 related post titles related to first tag on current post */
     $post_tags = wp_get_post_tags( $post->ID );

     if ( $post_tags ) {
       echo '<h3>Related Posts</h3>';
       $first_tag = $post_tags[0]->term_id;

       $args = array(
         'tag__in'          =>     array( $first_tag ),
         'post__not_in'     =>     array( $post->ID ),
         'showposts'        =>     5,
         'caller_get_posts' => 1
       );

       $related_posts = new WP_Query( $args );

       if( $related_posts->have_posts() ) {
         while ( $related_posts->have_posts() ) : $related_posts->the_post(); ?>
           <p>
                <a href="<?= the_permalink() ?>" title="<?= the_title_attribute(); ?>">
                    <?= the_title(); ?>
                </a>
           </p>
        <?php endwhile; }
     }
}

#4 Display a List of the Most Popular Posts

Displaying your most popular posts is a good way to make visitors stay longer on your blog. By popular post, I would pick up those posts that receive the most number of comments. In other words, more the number of comments, more is the number of visitors landed on that post, hence bringing it into the list of popular posts!

There are free plugins available that will do the task for you, but I personally would suggest doing it without a plugin. More plugin you have, heavier the site becomes. So, why adding one more plugin only for this purpose? I would rather write a simple function and call it wherever required. You can create a Widget for this as well. Unlike Related Posts, Poular Posts are not bound to any tag and hence could be placed anywhere. But to keep things simple I am opting for the following simple function in theme’s functions.php file.

function get_popular_posts() {
  $query = "SELECT comment_count, ID, post_title 
            FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0, 5"; ?>
  <h2>Popular Posts</h2>;
  <ul>
     <?php $result = $wpdb->get_results( $query );
     foreach ( $result as $post ) {
       setup_postdata( $post );
       $post_id = $post->ID;
       $title   = $post->post_title;
       $commentcount = $post->comment_count;
       if ( $commentcount !== 0 ) { ?>
         <li>
             <a href="<?php echo get_permalink( $post_id ); ?>" title="<?php esc_attr( $title ) ?>">
                <?php echo $title ?>
             </a> [ <?php echo $commentcount ?> ]
         </li>
       <?php 
       } 
     } ?>
  </ul>
}

#5 Never Forget to allow visitors to Comment and Share your Posts

In order to engage your visitors and attract them towards your blog, allowing comments and sharing are the two most powerful tools. Think it like this. I have read an article and now want to express some of my thoughts, good or bad, about this article. Remember, this is very important for serious readers. But if I don’t find the option to write a few words, the site will fail to keep me engaged in the future and thus may well be loose a potential visitor. But on the other hand, when I am able to put up some words, this is a common practice, that I will come to the site and see if someone else have said anything. By this process, you are not only keeping your visitors engaged but also increasing the popularity of the article.

Sharing is another great feature you must have on your site. I have a tendency of sharing good articles on my social handles like Facebook, Twitter, LinkedIn etc. whenever I find interesting one. Remember, there are a large number of people out there who love to share information amongst others. By allowing your visitors to share your Blog, you are actually increasing the reach of your content and thus increasing the traffic towards your Blog.

There are good sharing plugins avalable out there and you can choose the one that best suited your need. Here is a list of popular Social Media sharing plugins for WordPress that I find handy and do the job for you!

AddToAny Share Buttons
Sassy Social Share
Social Warfare
Social Media Share Buttons & Social Sharing Icons
Shared Counts

Leave a Reply

Your email address will not be published.