http://go.ad2up.com/afu.php?id=665574

Top 15 WordPress Hacks to make Website Better

WordPress is one of the fantastic tools that are used steadily over the web. There are number of plugins in wordpress that provides additional functionality to the wordpress sites. But, you cannot customize these plugins in your own way. But, if want to customize your website then you need to use wordpress hacks to make your website better. Moreover, using wordpress hacks on your website will reduce the extra load on your website that is caused due to plugins. This will make your website faster. So, here are top 15 wordpress hacks to make your website better.

WordPress Hacks to make Website Better

WordPress Hacks to make Website Better

Enabling the Shortcodes in Widgets

The widgets always tend to give a beautiful look to our website. These widgets are the indispensable part of every website.

  • Widgets are used to enhance the site appearance
  • These shortcodes can be used to add widgets to the site
  • You can use a filter to add widgets-
add_filter( ‘widget_text’, ‘do_shortcode’ );

Create TinyURLs on Fly

You can create the short URLs for your website URL. These short URLs can be used for sharing your stuff on social media platform. All you have to do is:

1. Open functions.php file

2. Paste the code given below

3. functiongetTinyUrl($url){

4.     $tinyurl=file_get_contents(“http://tinyurl.com/api-create.php?url=”.$url);

5.     return$tinyurl;

6. }

7. Open your single.php file and paste the following in the loop:

8. <?php

9. $turl=getTinyUrl(get_permalink($post->ID));

10.echo’Tiny Url for this post: <a href=”‘.$turl.'”>’.$turl.'</a>’

11.?>

Moving Navigation Menu to Center

You can decide the positioning of your logo, header length, or other elements like navigation menu of your website according to your needs. You can move the navigation menu to center to make it look in place. Here is the code to do the same.

1 #navigation {
2      position: relative;

 

3 }
4  #main-nav {

 

5      clear: left;
6      float: left;

 

7      list-style: none;
8      margin: 0;

 

9      padding: 0;
10      position: relative;

 

11      left: 50%;
12      text-align: center;

 

13 }
14  .nav li {

 

15      display: block;
16      float: left;

 

17      list-style: none;
18      margin: 0;

 

19      padding: 0;
20      position: relative;

 

21      right: 50%;
22 }

 

23  .nav li.hover, .nav li.hover {
24      position: relative;

 

25 }
26

 

27 .nav li ul li {
28      left: 0;

Resize Images on Fly

Manually resizing your images is a boring job. You can resize your images on fly by using the script given below:

<img src=”/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1″alt=”Screenshot”/>

Make Circular Avatars Squarish

Your wordpress theme may present the avatar images in circular forms. But most of the webmasters will prefer to display these images in form of square boxes. Here is the code for changing the Avatars.

1 #post-author .profile-image img, #comments .avatar img {
2 border-radius: 0;

 

3 -moz-border-radius: 0;
4 -webkit-border-radius: 0;

 

5 }

Removing Title from a particular page

There are number of tools to remove the title from different pages of your website, but what if you wish to remove the title from single page. You can use this simple code to do so-

1 .page-id-xxxx .title {
2 display: none;

 

3 }

Display Related Post without Plugin

Related post is one of the most effective ways to keep your visitors for long on your website. You can use plugins to do so, but it will increase load times of your site. You can use a code to show the related post on your site.

  • Open single.php
  • Now paste the code in this file

1. <?php

2. //for use in the loop, list 5 post titles related to first tag on current post

3. $tags=wp_get_post_tags($post->ID);

4. if($tags){

5.   echo’Related Posts’;

6.   $first_tag=$tags[0]->term_id;

7.   $args=array(

8.     ‘tag__in’=>array($first_tag),

9.’post__not_in’=>array($post->ID),

10.   ‘showposts’=>5,

11.   ‘caller_get_posts’=>1

12.   );

13. $my_query=newWP_Query($args);

14. if($my_query->have_posts()){

15.   while($my_query->have_posts()):$my_query->the_post();?>

16.     <p><a href=”<?phpthe_permalink()?>” rel=”bookmark” title=”Permanent Link to <?phpthe_title_attribute();?>”><?phpthe_title();?></a></p>

17.     <?php

18.   endwhile;

19. }

20.}

21.?>

Disable the HTML Comments

The HTML in the comments section of your website might lead to spammy comments and this might cause repercussions to your website. This is because most of the people disable their HTML comments.

  • It will make your website spam free
  • You need to implement a code on function.php file of your website
1 //As soon as someone comments
2 function plc_comment_post( $incoming_comment ) {
3     // convert everything in a comment to display literally
4     $incoming_comment[‘comment_content’] = htmlspecialchars($incoming_comment[‘comment_content’]);
5     // the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
6     $incoming_comment[‘comment_content’] = str_replace( “‘”, ‘&apos;’, $incoming_comment[‘comment_content’] );
7     return( $incoming_comment );
8 }
9 // This will occur before a comment is displayed
10 function plc_comment_display( $comment_to_display ) {
11     // Put the single quotes back in
12     $comment_to_display = str_replace( ‘&apos;’, “‘”, $comment_to_display );
13     return $comment_to_display;
14 }
15 add_filter( ‘preprocess_comment’, ‘plc_comment_post’, ”, 1 );
16 add_filter( ‘comment_text’, ‘plc_comment_display’, ”, 1 );
17 add_filter( ‘comment_text_rss’, ‘plc_comment_display’, ”, 1 );
18 add_filter( ‘comment_excerpt’, ‘plc_comment_display’, ”, 1 );
19 // This stops WordPress from trying to automatically make hyperlinks on text:
20 remove_filter( ‘comment_text’, ‘make_clickable’, 9 );

Making Top Navigation More Visible

The menu on navigation bar of your site is ignorable most of the times. You can move this menu around using the short code-

#top-nav {float: right;}

List Upcoming Posts

If you are scheduling the posts for publishing on your site, you can also display them on the list. This can help your RSS subscribers to know what is coming up in few days. Here is the code to do the same.

<div id=”zukunft”>

<div id=”zukunft_header”><p>Future events</p></div>

<?phpquery_posts(‘showposts=10&post_status=future’);?> <?phpif(have_posts()):while(have_posts()):the_post();?>  <div>

<pclass><b><?phpthe_title();?></b><?phpedit_post_link(‘e’,’ (‘,’)’);?><br/>

<spanclass=”datetime”><?phpthe_time(‘j. F Y’);?></span></p>  </div>

<?phpendwhile;else:?><p>No future events scheduled.</p><?phpendif;?>

</div>

Delay Publishing of your post on RSS Feeds

You might commit mistakes while writing the website post, but the posts might be sent to the RSS feed directly after publishing. These minor mistakes can be costly for you. But delaying the post from getting published on RSS Feeds can be really helpful in this case.

  • You just need to add the code to functions.php file in your site’s backend
  • This code will delay publishing of post to the RSS feeds according to the time set
1 function publish_later_on_feed($where) {
2 global $wpdb;
3 if ( is_feed() ) {
4 $time_now = gmdate(‘Y-m-d H:i:s’);
5 $time_delay = ’15’; // integer
6 $time_span = ‘MINUTE’; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
7 $where = ” AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, ‘$time_now’) > $time_delay “;
8 }
9 return $where;
10 }
11 add_filter(‘posts_where’, ‘publish_later_on_feed’);

Create ‘Send to Facebook’ Button

This wordpress hack is used to create a send to facebook button for your wordpress website. You just need to open single.php and paste the following code on loop:

<a href=”http://www.facebook.com/sharer.php?u=<?phpthe_permalink();?>&t=<?phpthe_title();?>” target=”blank”>Share on Facebook</a>

Let RSS feed Contain Post’s Featured Image

If you are using pictures in your post, it will add a beautified look to your post. This gives extra push to your website’s visitors and it will make your audience share your post more over the social networks. Enabling the post featured image on RSS feeds will you significantly.

  • It makes the post visually attractive
  • It will improve the social shares of your website
  • The code to do so is:
1 add_filter(‘the_content_feed’, ‘rss_post_thumbnail’);
2 function rss_post_thumbnail($content) {
3 global $post;
4 if( has_post_thumbnail($post->ID) )
5 $content = ‘<p>’ . get_the_post_thumbnail($post->ID, ‘thumbnail’) . ‘</p>’ .$content;
6 return $content;
7 }

Personalize Dashboard with a Logo

You can personalize the logo of your dashboard using the following code. The wordpress logo can be changed to other logo of your choice.

1 add_action(‘admin_head’, ‘custom_logo’);
2 function custom_logo() {

 

3 echo ‘
4 <style type=”text/css”><!–

 

5 #header-logo { background-image: url(‘.get_bloginfo(‘template_directory’).’/images/custom-logo.gif) !important; }
6 –></style>’;

 

7 }

Redirect the Users after they Log In

If any user is logged in into your website, you can redirect him/her to URL of your choice. Just add the following code to functions.php file of your website

1 <?php function redirect_user_on_role() { //retrieve current user info global $current_user; get_currentuserinfo(); //If login user role is Subscriber if ($current_user->user_level == 0)
2 {

 

3 wp_redirect( home_url() ); exit;
4 }

 

5 //If login user role is Contributor
6 else if ($current_user->user_level > 1)

 

7 {
8 wp_redirect( home_url() ); exit;

 

9 }
10 //If login user role is Editor

 

11 else if ($current_user->user_level >8)
12 {

 

13 wp_redirect( home_url() ); exit;
14 }

 

15 // For other roles
16 else

 

17 {
18 $redirect_to = ‘http://google.com/’;

 

19 return $redirect_to;
20 }

 

21 }
22 add_action(‘admin_init’,’redirect_user_on_role’);

 

23
24 ?>