35+ Most Essential WordPress Tricks and Hacks

wordpress WordPress certainly doesn’t need any kind of introduction amongst bloggers and designers. Today there are hundreds of wordpress blogs around the web some on shared hosting and some on dedicated server. To stand out among these is in itself one of the most difficult task a blogger would find itself in.

Ofcourse posting articles of high quality is the answer to standing in the elite group, but along with quality you also need other things so that your readers could expect really different things in your blog. Then that difference can be as little as the color of the comments.

What is a Hack in WordPress: A way of doing something that involves adding quick-and-dirty bit of code to make a piece of software do what you want, rather than using a prepackaged (and possibly more elegant) solution like a plugin.

Many times you would have come across wordpress blogs and said to yourself “How did he do it?”, “Is that a plugin? If not, how to use it”, “can i do it in my blog?”
For answering all such questions we have compiled here some of the most essential worpress hacks that could make your blogging life easier and help you getting the best out of WordPress that too without using any plugins.

We have categorized the list into Post Hacks, Comment Hacks, Tags,categories and Archives hacks, Search hacks and Other General Hacks

WordPress Post Hacks


Create Your Own Popular Posts content in the sidebar


Highlighting the most popular posts on your site is a great way to send new visitors to your very best content and win them over.

There are a few different ways you can do this, and quite a few plugins out there to help. But why not base it on the number of comments? If you write a post that makes people talk, it must be a well written post (Most of the time…).

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

Source

Get the first Image from the Post and display it


Most WordPress users are using custom fields to display thumbs on their blog homepage. It is a good idea, but do you know that with a simple php function, you can grab the first image from the post, and display it. Just read on.

First, paste this function on your functions.php file.

function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', 
$post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}

Once done, you can simply call the function within the loop to display the first image from the post:

<?php echo catch_that_image() ?>

Source

Display Related Posts without using Plugins


Displaying related posts is a very great way to help visitors staying longer on your blog. You can use a plugin, but you also can use tags and a custom code to show related posts. Let’s see how to do!

This code will display related posts based on the current post tag(s). It must be pasted within the loop.

<?php
//for use in the loop, list 5 post titles related to first tag on 
//current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
  echo 'Related Posts';
  $first_tag = $tags[0]->term_id;
  $args=array(
    'tag__in' => array($first_tag),
    'post__not_in' => array($post->ID),
    'showposts'=>5,
    'caller_get_posts'=>1
   );
  $my_query = new WP_Query($args);
  if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <p><a href="<?php the_permalink() ?>" rel="bookmark" title="
      Permanent Link to <?php the_title_attribute(); ?>">
      <?php the_title(); ?></a></p>
      <?php
    endwhile;
  }
}
?>

Source

Automatically insert content after each post


Most blogs automatically displays some text after each post, for exemple to ask readers to subscribe to their rss feed. This text is very often hardcoded. Why not using function.php instead, and be able to keep the text when you’ll switch theme?

To achieve this recipe, simply paste the following code in your functions.php file. By using functions.php, you’ll not have to re-insert this code if you switch themes.

function insertFootNote($content) {
        if(!is_feed() && !is_home()) {
                $content.= "<div class='subscribe'>";
                $content.= "<h4>Enjoyed this article?</h4>";
                $content.= "<p>Subscribe to our  <a href='http://
                feeds2.feedburner.com/WpRecipes'>RSS feed</a> 
                and never miss a recipe!</p>";
                $content.= "</div>";
        }
        return $content;
}
add_filter ('the_content', 'insertFootNote');

Source

Make your new posts stands out


Why not giving a special style to the posts published less than 24 hours ago, to let your readers know about the fact they’re new? Here’s a simple code to do it.

To achieve this recipe, edit your index.php file and look for the loop. Replace it with that one:

<?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post();
        $currentdate = date('Y-m-d',mktime(0,0,0,date('m'),date('d'),
        date('Y')));
        $postdate = get_the_time('Y-m-d');
        if ($postdate==$currentdate) {
            echo '<div class="post new">';
        } else {
            echo '<div class="post">';
        } ?>
        <a href="<?php the_permalink() ?>" rel="bookmark">
        <?php the_title(); ?></a>
        <?php the_time('j F Y'); ?>
        </div>
    <?php endwhile; ?>
<?php endif; ?>

The above code will add the css class new if the post was published less than 24 hours ago. Then, you just have to modify your stylesheet a bit:

.post{
    /* CSS style for "normal" posts */
}

.post.new {
    /* CSS style for newer posts */
}

Source

Display Author Information For Posts


By using the codes below in your single.php file, you will pull the information from the post author’s profile on your blog and show a bit about them. This is especially useful if you’ve got a lot of authors on your blog.

<div id="author-info">
<div id="author-image">
    	<a href="<?php the_author_meta('user_url'); ?>">
        <?php echo get_avatar( get_the_author_meta('user_email'), '80',
        '' ); ?></a></div>
<div id="author-bio">
<h4>Written by < ?php the_author_link(); ?></h4>

< ?php the_author_meta('description'); ?>
</div>
</div>
<!--Author Info-->

Source

WordPress function to display your posts words count


Simply open your functions.php file and paste this function in it:

function wcount(){
    ob_start();
    the_content();
    $content = ob_get_clean();
    return sizeof(explode(" ", $content));
}

Once done, you can call the function within the loop to get the number of words of the current post:

<?php echo wcount(); ?>

Source

Display Sticky Posts in One Area


You can change the number 5 the amount of posts you want to show in your page. You can also display full posts by changing ‘the_excerpt’ value to ‘the_content’.

<?php
$sticky = get_option('sticky_posts');
rsort( $sticky );
$sticky = array_slice( $sticky, 0, 5);
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );

if (have_posts()) :
while (have_posts()) : the_post();
the_title();
the_excerpt();
endwhile;
endif;

?>

Source

Get posts published between two particular dates


WordPress loop is very powerful, as well as the query_posts() function, which allow you to specify some parameters for the loop to retrieve posts. Though, there’s no built-in function or parameter to get posts between two dates. Let’s solve that.

Open your index.php file and find the loop. Just before the loop starts, paste the following code. Of course, don’t forget to change the dates on line 3 according to your needs.

<?php
function filter_where($where = '') {
$where .= " AND post_date >= '2009-05-01' AND post_date <= 
'2009-05-15'";
return $where;
  }
add_filter('posts_where', 'filter_where');
query_posts($query_string);
?>

Source

WordPress Comments Hacks


Automatically refuse spam comments on your WordPress blog


Spam is a nuisance, and you know it. Happilly, WordPress users have Akismet, which help a lot to fight spam. But what about protecting your blog even more? This recipe might help

Paste the following code in your functions.php. Comment that contain any of the words contained within the $bad_comment_content array will be automatically rejected.


function in_comment_post_like($string, $array) {
foreach($array as $ref) { if(strstr($string, $ref)) { return true; } }
return false;
}
function drop_bad_comments() {
if (!empty($_POST['comment'])) {
$post_comment_content = $_POST['comment'];
$lower_case_comment = strtolower($_POST['comment']);
$bad_comment_content = array(
'viagra',
'hydrocodone',
'hair loss',
'[url=http',
'[link=http',
'xanax',
'tramadol',
'russian girls',
'russian brides',
'lorazepam',
'adderall',
'dexadrine',
'no prescription',
'oxycontin',
'without a prescription',
'sex pics',
'family incest',
'online casinos',
'online dating',
'cialis',
'best forex',
'amoxicillin'
);
if (in_comment_post_like($lower_case_comment, $bad_comment_content)) {
$comment_box_text = wordwrap(trim($post_comment_content), 80, "\n ", true);
$txtdrop = fopen('/var/log/httpd/wp_post-logger/nullamatix.com-text-area_dropped.txt', 'a');
fwrite($txtdrop, " --------------\n [COMMENT] = " . $post_comment_content . "\n --------------\n");
fwrite($txtdrop, " [SOURCE_IP] = " . $_SERVER['REMOTE_ADDR'] . " @ " . date("F j, Y, g:i a") . "\n");
fwrite($txtdrop, " [USERAGENT] = " . $_SERVER['HTTP_USER_AGENT'] . "\n");
fwrite($txtdrop, " [REFERER ] = " . $_SERVER['HTTP_REFERER'] . "\n");
fwrite($txtdrop, " [FILE_NAME] = " . $_SERVER['SCRIPT_NAME'] . " - [REQ_URI] = " . $_SERVER['REQUEST_URI'] . "\n");
fwrite($txtdrop, '--------------**********------------------'."\n");
header("HTTP/1.1 406 Not Acceptable");
header("Status: 406 Not Acceptable");
header("Connection: Close");
wp_die( __('bang bang.') );
}
}
}
add_action('init', 'drop_bad_comments');

Source

Number your comments


Open comments.php and find the following line:


<?php foreach ($comments as $comment) : ?>

Just above this line, initialize a counter variable:


<?php $i = 0; ?>

Just after this line, increment the counter:


<?php $i++; ?>

Now, you just have to echo the $i variable to get the number of the current comment. Paste this code anywhere on your comments loop:


<?php echo $i; ?>

source
Your comments are now numbered!

Batch deleting spam comments on a WordPress blog


delete more than 6000 spam comments that you received on your blog.

First of it all, backup your WordPress database. Then, login to your phpmyadmin, select your WordPress blog database and click on SQL:

Then, insert the following sql command:


DELETE from wp_comments WHERE comment_approved = '0';

source

All non-approved comments will be deleted. But instead of having such trouble next time, you should definitely install Akismet!

Highlight author comments in WordPress


This is useful to make the author comments pop in the comment section, so the readers find the answers to their questions quicker. It can also avoid people pretending they are the author by commenting with his name.

To style the author’s comments differently, you should open the comments.php template file and look for this piece of code (or something looking like it).


<li class=”<?php echo $oddcomment; ?>” id=”comment…

Replace it by this one.


<li class=”<?php
/* Only use the authcomment class from style.css if the user_id is 1 (admin) */
if (1 == $comment->user_id)
$oddcomment = “authcomment”;
echo $oddcomment;
?>” id=”comment…

Then you can style it in your stylesheet with something like this.


.authcomment {
background-color: #B3FFCC !important;
}

source

Alternating Colors For Comments


You might want to have alternating row colors for your comments, to make a clearer separation. Alternating rows make it easier to distinguish different comments. Doing this is relatively very easy.

Open your theme css file, and paste this at the bottom:


.color1 {
background-color: #DBDBDB;
}
.color2 {
background-color: #EEEEEE;
}

At the VERY top of comments.php file, put this on a line of it’s own.


<?$i;?>

Now scroll down to find this part of the code


<?php foreach ($comments as $comment) : ?>
<div class="commentbox">
<div class="commentid">

Now replace the above by


<?php foreach ($comments as $comment) : ?>
<div id="commentbox" class="<?=($i%2)?"color1":"color2";$i++;?>">
<div class="commentid">

source

Displaying Recent Comments


Recent comments are very helpful for readers to comment on any topic about any ongoing discussion. To display your most recent comments, you will have to modify your functions.php file from the theme folder. If the functions.php file is not present, make a new text file, name it functions.php and add it to your theme folder. Add the following code to it and save the file.


<?php
function recent_comments($src_count=10, $src_length=60, $pre_HTML='<ul>', $post_HTML='') {
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type,
SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC
LIMIT $src_count";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {
$output .= "<li><a href=\"" . get_permalink($comment->ID) . "#comment-" . $comment->comment_ID . "\" title=\"on " . $comment->post_title . "\">" . strip_tags($comment->com_excerpt) ."...</a></li>";
}
$output .= $post_HTML;
echo $output;
}
?>

Now, wherever you want to show the list of recent comments, just add this code.


<?php recent_comments(); ?>

source

How to Separate WordPress Comments and Trackbacks


Trackbacks are the messages displayed in the comments list whenever another blog links back to one of your posts. If you use trackbacks on your blog, it is best if they are not mixed with the comments. The comments are a conversation between real people. Having machine-generated links in the middle of that will only serve to disrupt the conversations.

In order to separate the comments and trackbacks, you just need to follow these steps.

Open comments.php, and search for the following line


<?php foreach ($comments as $comment) : ?>

After it, paste the following


<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

Now look for


<?php endforeach; /* end for each comment */ ?>

And before it, paste


<?php } else { $trackback = true; } /* End of is_comment statement */ ?>

Now your list of comments will continue to display as normal, but without any trackbacks or pingbacks. Now we will add a second comments loop for the trackbacks.

Look for the following line


<?php else : // this is displayed if there are no comments so far ?>

And before it, paste this: (The “Trackbacks” title line can be deleted if you don’t want a heading to be shown)


<?php if ($trackback == true) { ?>
<h3>Trackbacks</h3>
<ol>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php } ?>
<?php endforeach; ?>
</ol>
<?php } ?>

source

WordPress Tags,Categories and Archives Hacks


Find WordPress category ID


Some themes requires that you fill a form field with a category ID. It may be easy to find a category ID if you’re an advanced WordPres user, but what about beginners? Here’s a very simple manner to find any category ID.

Once you’re logged in your WordPress dashboard, go to Manage and then in Categories.
Simply put your mouse cursor on the “edit” link related to the category you want to know the ID and look on your browser’s status bar: As you can see on the screenshot below, 1 is the id of the category.

categ

Display Certain Categories in a Menu


In many cases, users only want to display certain categories in their navigation menu at the top of the page. There are limited spots, that can only be filled by top categories, but if you use the default wp_list_categories code, it will show all categories. This is why this hack below comes in very handy when you want to create a navigation menu and only display certain categories.


<ul class="navmenubar" style="float:left; width:730px;">
<?php wp_list_categories('orderby=name&include=7,9,19,16,1,5,17,23'); ?>
</ul>

Source
Note, you can also change the ‘include’ text to ‘exclude’ and show all categories and exclude those that you don’t want displayed. The numbers displayed in the code are the category IDs. Remember since WordPress shows categories in a list format, you will need to edit the CSS in order to make it work.

Display Tags In A Dropdown Menu


I never liked tag clouds, for the simple reason that most of the time, they’re aren’t readable properly. Here is the solution to this problem: Displaying tags in a dropdown menu.

The first thing to do is to create the function. Paste the following code to your functions.php file:


<?php
function dropdown_tag_cloud( $args = '' ) {
$defaults = array(
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
'exclude' => '', 'include' => ''
);
$args = wp_parse_args( $args, $defaults );

$tags = get_tags( array_merge($args, array('orderby' => 'count', 'order' => 'DESC')) ); // Always query top tags

if ( empty($tags) )
return;

$return = dropdown_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
if ( is_wp_error( $return ) )
return false;
else
echo apply_filters( 'dropdown_tag_cloud', $return, $args );
}

function dropdown_generate_tag_cloud( $tags, $args = '' ) {
global $wp_rewrite;
$defaults = array(
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC'
);
$args = wp_parse_args( $args, $defaults );
extract($args);

if ( !$tags )
return;
$counts = $tag_links = array();
foreach ( (array) $tags as $tag ) {
$counts[$tag->name] = $tag->count;
$tag_links[$tag->name] = get_tag_link( $tag->term_id );
if ( is_wp_error( $tag_links[$tag->name] ) )
return $tag_links[$tag->name];
$tag_ids[$tag->name] = $tag->term_id;
}

$min_count = min($counts);
$spread = max($counts) - $min_count;
if ( $spread <= 0 )
$spread = 1;
$font_spread = $largest - $smallest;
if ( $font_spread <= 0 )
$font_spread = 1;
$font_step = $font_spread / $spread;

// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
if ( 'name' == $orderby )
uksort($counts, 'strnatcasecmp');
else
asort($counts);

if ( 'DESC' == $order )
$counts = array_reverse( $counts, true );

$a = array();

$rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';

foreach ( $counts as $tag => $count ) {
$tag_id = $tag_ids[$tag];
$tag_link = clean_url($tag_links[$tag]);
$tag = str_replace(' ', ' ', wp_specialchars( $tag ));
$a[] = "\t<option value='$tag_link'>$tag ($count)</option>";
}

switch ( $format ) :
case 'array' :
$return =& $a;
break;
case 'list' :
$return = "<ul class='wp-tag-cloud'>\n\t<li>";
$return .= join("</li>\n\t<li>", $a);
$return .= "</li>\n</ul>\n";
break;
default :
$return = join("\n", $a);
break;
endswitch;

return apply_filters( 'dropdown_generate_tag_cloud', $return, $tags, $args );
}
?>

Once done, you can use the function to get your dropdown menu of tags. Just open the file where you want the list to be displayed (Most of the time it is sidebar.php) and paste the following code:


<select name="tag-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value="#">Liste d'auteurs</option>
<?php dropdown_tag_cloud('number=0&order=asc'); ?>
</select>

source

Display Categories in a drop down Menu


To add a good looking drop down that will list all your existing categories, insert the following code in your blog template. You can do it either in your sidebar.php file or anywhere in the index.php. This is the code :-


<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript><input type="submit" value="View" /></noscript>
</form>

source

Display Archives in a drop down Menu


Just like in categories, you can have your monthly archives listed in a drop down. Add the following code to your template files :-


<select name=\"archive-dropdown\" onChange='document.location.href=this.options[this.selectedIndex].value;'>
<option value=\"\"><?php echo attribute_escape(__('Select Month')); ?></option>
<?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select>

source

Exclude Categories From Search


If for some reason, you’d like to exclude some categories from searches, you have to tweak WordPress a bit because there’s no built-in solution to this problem. Happilly, here’s a code to do that job!

To achieve this recipe, replace the categories IDs on line 3 and paste the following code on your search.php template:


<?php if( is_search() ) :
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("s=$s&paged=$paged&cat=1,2,3");
endif; ?>

source
You are done!!!!!!!

Exclude Categories from your RSS Feed


Depending to your blog structure, it may be interesting to exclude some categories from your rss feeds. If you always wanted to find a clean way to do it, I’m pretty sure this recipe will make you happy.

Before starting to code, you’ll have to know the numeric ID of the categories you want to exclude. If you don’t know how to get the ID of a particular category, just read the first post in the category “WordPress Tags,Categories and Archives Hacks”.

Once you have the ID of the categories you want to exclude from your rss feed, open the functions.php file from your theme. If your theme doesn’t have a functions.php file, create one.

Paste the following code in it:


function myFilter($query) {
if ($query->is_feed) {
$query->set('cat','-5'); //Don't forget to change the category ID =^o^=
}
return $query;
}

add_filter('pre_get_posts','myFilter');

source

Display your categories in two columns


The stadard wp_list_categories() functions echoes a list of all your categories. Let’s see how we can easily force the display of categories on two columns.

Simply paste the following piece of code where you’d like your categories to be displayed


<?php
$cats = explode("<br />",wp_list_categories('title_li=&echo=0&depth=1&style=none'));
$cat_n = count($cats) - 1;
for ($i=0;$i<$cat_n;$i++):
if ($i<$cat_n/2):
$cat_left = $cat_left.'<li>'.$cats[$i].'</li>';
elseif ($i>=$cat_n/2):
$cat_right = $cat_right.'<li>'.$cats[$i].'</li>';
endif;
endfor;
?>
<ul class="left">
<?php echo $cat_left;?>
</ul>
<ul class="right">
<?php echo $cat_right;?>
</ul>

source
Then, just save the file, and enjoy!


WordPress Search Hacks


Display the number of results in WordPress search


WordPress users know it: Search is definitely one of WordPress weak point. Today, let’s see how to get the number of results the search returned, and display it (proudly!) on our blog.

Open your search template file, search.php. In it, search for the following:


<h2 class="pagetitle">Search Results</h2>

Now replace this with:


<h2 class="pagetitle">Search Results for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' — '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h2>

That’s all, you’re done!

Highlight the Search Terms in Results


When you search on Google or any other major search engine, the words you searched for are highlighted in the results to make it easier for you to scan. We can do the same with your search results page.

In search.php, search for the following:


<?php the_title(); ?>

This is the code for showing the title of each of the results. In the default theme, it will be wrapped up in a line like this:


<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>

Now, replace the part with:


<?php echo $title; ?>

Finally, before this line, paste the following:


<?php $title = get_the_title(); $keys= explode(" ",$s); $title = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">\0</strong>', $title); ?>

source

Make your WordPress Search Results Unlimited


Sometimes you may not want your search results to be limited by the confines of the standard WordPress Loop. This is a quick code hack to allow a search to return unlimited results, altering the standard WordPress Loop by using a custom query. You can do this in a few different ways. If you have a search template, in search.php you can simple add the following line of code above your Loop.

Find:


<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

Add:


<?php $posts=query_posts($query_string . '&posts_per_page=-1'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

source

Other General WordPress Hacks


Add Social Bookmarking Buttons in your WordPress Blog without plugins


In this post I will be highlighting the manual codes that we can use to create share buttons for Retweet, Digg, Buzz, DesignFloat, StumbleUpon, FShare, Delicious, DZone, Reddit, Technoraiti.
View Source Article

Display your Feedburner count in full text


Are you using feedburner? Probably yes, just as a lot of bloggers do. If you don’t like the chicklet dedicated to display your feedburner count, just read this recipe which is a new method to get your feedburner count in text mode.

To display your feedburner count in full text on your WordPress blog, simply paste the following on any of your theme file, for exemple sidebar.php:


<?php
$fburl=”https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=YourURL“;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $fburl);
$stored = curl_exec($ch);
curl_close($ch);
$grid = new SimpleXMLElement($stored);
$rsscount = $grid->feed->entry['circulation'];
echo $rsscount;
?>

source

Display the total number of your Twitter followers on your WordPress blog


If you’re on Twitter, you probably display the number of your followers on your blog, using the chicklet from TwitterCounter.com. Today, I’m going to show you how to display your followers in full text mode.

The first thing to do is to paste the following php functions on the functions.php file from your WordPress blog theme:


function string_getInsertedString($long_string,$short_string,$is_html=false){
if($short_string>=strlen($long_string))return false;
$insertion_length=strlen($long_string)-strlen($short_string);
for($i=0;$i<strlen($short_string);++$i){
if($long_string[$i]!=$short_string[$i])break;
}
$inserted_string=substr($long_string,$i,$insertion_length);
if($is_html && $inserted_string[$insertion_length-1]=='<'){
$inserted_string='<'.substr($inserted_string,0,$insertion_length-1);
}
return $inserted_string;
}

function DOMElement_getOuterHTML($document,$element){
$html=$document->saveHTML();
$element->parentNode->removeChild($element);
$html2=$document->saveHTML();
return string_getInsertedString($html,$html2,true);
}

function getFollowers($username){
$x = file_get_contents("http://twitter.com/".$username);
$doc = new DomDocument;
@$doc->loadHTML($x);
$ele = $doc->getElementById('follower_count');
$innerHTML=preg_replace('/^<[^>]*>(.*)<[^>]*>$/',"\\1",DOMElement_getOuterHTML($doc,$ele));
return $innerHTML;
}

Then, simply paste the following anywhere on your theme files. Just replace our username with yours.


<?php echo getFollowers("artatm")." followers"; ?>

source

Manually reset your WordPress password


What to do if you lost your WordPress password? The easier is to use PhpMyAdmin and execute a simple SQL query to update it. Here’s how to proceed.

To achieve this recipe, login to your PhpMyAdmin, select your WordPress database and click on the “SQL” button to open the SQL query window.

Then, paste the following code in the window textarea. Don’t forget to modify the password and username before executing it. Also, make sure you have a backup of your database before executing any SQL queries to your database.


UPDATE 'wp_users' SET 'user_pass' = MD5('PASSWORD') WHERE 'user_login' ='admin' LIMIT 1;

source

Automatically provide tinyurls for your WordPress blog posts


Are you on Twitter? I am. This service make an intensive use of tinyurls in order to reduce the size of urls. Why not provide automatically provide a tinyurl to your readers so they can use it on Tweeter?

To achieve this recipe, simply open your functions.php file and paste the following code


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

On your single.php file, paste the following within the loop:


<?php
$turl = getTinyUrl(get_permalink($post->ID));
echo 'Tiny Url for this post: <a href="'.$turl.'">'.$turl.'</a>'
?>

source

Display today’s date on your WordPress blog


Many blogs displays the current date on their blog header. It looks profesional, and it is also useful, especially if your blog posts are dated. Here is a very easy way to add today’s date on your WordPress blog.

Open your header.php file (or any other file) and paste the following code:


<?php echo date('l jS F Y'); ?>

source

Display page loading time + number of queries


Do you ever asked yourself how long it took for your page to load, or how many sql queries were executed? If yes, here is a simple code to insert on your template.

Nothing hard here. Simply paste the following code on your footer.php file


<?php echo get_num_queries(); ?> queries in <?php timer_stop(1); ?> seconds.

source

Hide WordPress version


In order to secure your blog, is it a good thing to hide the meta version appearing within the and html tag of your blog. Since WP 2.5, the version is inserted automatically, and can’t be removed as easily at before. Except if you use that hack !

This hack isn’t hard to do at all. Just open the functions.php file from your theme and add the following line of code:


remove_action('wp_head', 'wp_generator');


Am I missing Something??


If Anything Missing related to wordpress hacks let me know. If you have any suggesion on this topic please post in comment section we will try to improve our topic and content.

Passing 1z0-046 exam is not difficult if you have accurate resources. Just go through the braindumps and pass your 642-902 in first attempt guaranteed.

A music lover, creativity is all that he has in his mind and a very avid reader. He is the Founder of ArtAtm. He is a web designer by profession from India. You may want to Follow Him On Twitter

Rocky – who has written posts on Artatm - Creative Art Magazine.


67 Responses to “35+ Most Essential WordPress Tricks and Hacks”
  1. Dee

    Great bunch of solutions! Thank you for sharing.

    For content heavy sites going through the default format of categories / tags can get very tedious. Perhaps you could add a tip on how to add a year-wise dropdown of articles?

  2. Ally

    Some of these will come in very handy! Thank you!

  3. Joomla template maken

    When I comes to HTML modifying, I am on to it! I tried some tweaks and I would say, this is really recommendable for other WP webmasters! Keep it up!

  4. Design Nirvana

    Thanks for this wonderful tips… It was really helpful.

  5. Daniel Rosca

    I do like this article since it encourages the WordPress users to skip some plugins and add few pieces of code to functions.php to get the same results. Of course, it’s not the most recommended way to do it, because you may lose all those functions if the theme is going to be updated after the edits, but all those can be easily converted to Must Use plugins. Thanks for sharing all those tips.

  6. Deven

    Really very helpful. surely will go for few.

  7. bestjobstore

    Wow good , do you have any plugin or code that post excerpt of my post automatically some sites like facebook,twitter , pinterest, tumbler,stumblupon etc in one go

  8. shubhangi

    Great , can you have any idea for creating thumbnail for video content if you have please add here.

  9. Sergey Oganesyan

    Thank you, very informative

  10. webdesign

    We have categorized the list into Post Hacks, Comment Hacks, Tags,categories and Archives hacks, Search hacks and Other General Hacks

  11. Juliawan

    how to highlight author comment , I am try it is not work, how to fix it?

  12. Robin Paul

    Oh My God. i did not know this type of wordpress hacks. I am going to implement all of these tips to my wordpress knowledge

  13. Kiefer

    Just to remind you people who commented on this article that all the links are nofollow :)

  14. Joseph Buarao

    I really appreciate your post mate..

  15. Frenchie

    Excellent !!!! Thank you
    Ça fonctionne trés bien…

  16. Sumit nagpal

    Very helpful. Thanks For Share

  17. francois

    Thanks for these hacks ! I prefer use these than plugins :)

  18. Nice Post ……Thanks………….

Leave a Reply