Sunday, October 13, 2013

6 Useful WordPress Hacks

In line with Article 10 WordPress hacks easy to implement, discover six new useful hacks for your WordPress.

Definition WordPress hack: Element coded often inserted in the "function.php" file of your theme. The benefits of a hack are that it is much faster than a plugin, do not overload your blog and usually does not require updating.

Detect Visits In The Origin Mobile

Mobile browsing on the internet is increasing, so it is very useful to detect visits from users "mobile" and that, in order to redirect to a more appropriate and dedicated navigation smartphone or tablet page. To do this, you must firstly obtain complete information on Detect mobile browser website and transfer it in the directory of your theme, then change your header.php by placing the following code (do not forget to change the redirect page /your-website.com):

include('mobile_device_detect.php');
$mobile = mobile_device_detect();
if ($mobile==true) {
 header( 'Location: http://your-site.com/?theme=Your_Mobile_Theme' ) ;
}

Automatically resize The Images

If you use many images on your blog, then you know how tedious it is to have to always resize your images manually. Use this hack to automatically resize an image of your choice (width and height) for a more organized look. Just copy the following source code: script (click here) in a new document called "timthumb.php", place it in a folder on your site (eg: /scripts/) and call the image like this:

<img src="/scripts/timthumb.php?src=/images/the-name-of-your-image.jpg&h=150&w=150&zc=1" alt="" />

Show Your Best-Of Annual

This hack allows your visitors to see the top 5 most commented articles on your blog over a year. This is a great way to give back to your second chance. To view a different time, just change the dates. ? Place the following code in your sidebar or anywhere else:

<h2>My 5 most commented articles in 2011</h2>
<ul>
<?php
$result = $wpdb->get_results("SELECT comment_count,ID,post_title, post_date FROM $wpdb->posts WHERE post_date BETWEEN '2011-01-01' AND '2011-12-31' ORDER BY comment_count DESC LIMIT 0 , 5");
foreach ($result as $topten) {
 $postid = $topten->ID;
 $title = $topten->post_title;
 $commentcount = $topten->comment_count;
 if ($commentcount != 0) {
 ?>
 <li><a href="<?php echo get_permalink($postid); ?>"><?php echo $title ?></a></li>
 <?php }
}
?>
</ul>

Only Allow Your IP On Wp-Admin

If you do not have a collaborative blog and therefore multiple writers, you should be the only one allowed to visit the wp-admin directory. To increase the security of your site, enter your static IP address line 8. You can also add other IP addresses, if necessary, by creating a new line. Place the following code in your htaccess file.

AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Example Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
allow from xx.xx.xx.xx
</LIMIT>

An Insert Author Bio on Each Item

It is sometimes useful to view the Bio of the author of an article, whether on a multi-author blog and when your articles are listed. If your theme does not offer this feature, insert the following code in your functions.php file. The biography of the author will be automatically displayed at the end of each article:

function get_author_bio ($content=''){
 global $post;
$post_author_name=get_the_author_meta("display_name");
 $post_author_description=get_the_author_meta("description");
 $html="<div class='clearfix' id='about_author'>n";
 $html.="<img width='80' height='80' class='avatar' src='http://www.gravatar.com/avatar.php?gravatar_id=".md5(get_the_author_email()). "&default=".urlencode($GLOBALS['defaultgravatar'])."&size=80&r=PG' alt='PG'/>n";
 $html.="<div class='author_text'>n";
 $html.="<h4>Author: ".$post_author_name."</h4>n";
 $html.= $post_author_description."n";
 $html.="</div>n";
 $html.="<div class='clear'></div>n";
 $content .= $html;
 }
return $content;
}
add_filter('the_content', 'get_author_bio');

Redirect Your RSS Feeds To FeedBurner

Whenever a user follow a link from your default stream (http://www.your-site.com/feed), it will be redirected to, your FeedBurner feed (http://feeds.feedburner.com/your-site). With this hack, even a user of your RSS feed origin; will be automatically redirected to FeedBurner. Place the following code in your htaccess file.

# temp redirect wordpress content feeds to feedburner
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
 RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
 RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/votre-site [R=302,NC,L]
</IfModule>

Sources and resources for more hacks: Webdesignledger.


See more wordpress tutorial

Share it Please

0 comments:

Post a Comment

Copyright @ 2013 Johnny Gagnon blog. Designed by Templateism | Love for The Globe Press