Best wordpress tips and techniques of all time

WordPress hacks, here in this article we given Best wordpress tips and techniques of all time favorite for all wordpress developers. Code snippets will help you while developing wordpress plugin or theme.

Best wordpress tips and techniques of all time

I collected the best wordpress tricks and tips, Most wanted hacks, Most powerful wordpress techniques and tricks. I included code and there uses in this article. Every wordpress developer are looking for this.

Best wordpress tips and techniques of all time
Best wordpress tips and techniques of all time

Robots.txt file

Put valid Robots.txt file so search engine will crawl your site data.

For checking robots.txt file you should use following link

http://tool.motoricerca.info/robots-checker.phtml

Using Pretty Permalinks

Your blog should never have URLs that look like this: www.yourdomain.com/?pageid=21, just like humans, search engine crawlers do not recognize this type of information and is thus useless. Customizing pretty permalinks in WordPress will allow you to use URLs like: www.yourdomain.com/great-post, which are 100% recognizable and will contain keywords for your posts that will make them easier to be found in search engines.

WordPress SEO Plugins

SEO techniques like customizing post titles, description and keywords can be quite a huge task to do when using a bare WordPress theme. The free SEO plugin All In One SEO Pack can make the task 100 times easier and when installed presents options to easily optimize your blog posts and pages.

Random Post

Have you ever been to a site and saw this cool feature? They have a link in their top navigation to something like Stumbe! or Read Random Articles, or some other creative text. When you click on that link, it takes you to a page that displays one random page. Each time you refresh, you are delivered with a new post. Well this trick is just for you then.

You would need to follow the trick #1 in this article to create a custom page template. And simply paste this code in there:


<?php
query_posts(array('orderby' => 'rand', 'showposts' => 1));
if (have_posts()) :
while (have_posts()) : the_post(); ?>

<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>

<?php the_content(); ?>

<?php endwhile;
endif; ?>

Maintaining A Working Sitemap

A sitemap helps search engine crawlers to effectively identify pages and posts that should be indexed and made accessible to visitors through search engines. It is basically a file named sitemap.xml which is usually located within your blog’s root directory. The Google XML Sitemaps plugin will help you to easily create and update your sitemap when changes are made to your blog and it also notifies google and bing about the changes. This will significantly increase your site’s crawl rate.

Create a Resourceful 404 Page Design

The above tutorial lists some of the elements that you should have in a 404 page design. Check following designs.

https://purabtech.in/2010/03/14/how-to-create-404-page-in-wordpress-theme/

Effective Navigation Setup

Always ensure that your navigation links are properly structured and placed on your blog. Navigation links need to be relevant to the content they represent, should never be broken or point to pages that have no content. A crowded and poorly structured site navigation gets you nowhere with your readers and search engine crawlers.

Appropriate Tags For Images

Images play an important role in enhancing the look and feel of our blogs and can better capture the attention of our readers more than plain text alone. Images should be used sparingly and when used they need to be of reasonable sizes in terms of (kb) and should have title tags that describe the content they represent. Its very important to use titles that have a strong relation with the supporting post’s content.

Display Feedburner Subscriber Count as Text

Have you ever been to a site that is not using Feedburner button and is still showing subscriber count? Well they are probably using the trick we are about to share. Most designers use this trick to have custom styling and avoid the annoying feedburner button.

Simply copy and paste this code anywhere you like most likely sidebar.php


<?php
//get cool feedburner count
$whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=your feedburner id";

//Initialize the Curl session
$ch = curl_init();

//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Set the URL
curl_setopt($ch, CURLOPT_URL, $whaturl);

//Execute the fetch
$data = curl_exec($ch);

//Close the connection
curl_close($ch);
$xml = new SimpleXMLElement($data);
$fb = $xml->feed->entry['circulation'];
echo $fb;
//end get cool feedburner count
?>

You can wrap it around in styling to make it look like however you want.

Display Twitter follower count

display twitter follower count in your site and attract another user to follow you.

https://purabtech.in/2010/08/23/twitter-follower-count-php-wordpress/

Internal Linking To Related Articles

Linking to other related posts within your blog will help to direct search engine crawlers to other pages of your site and also provide an opportunity to enforce what those pages are about. This will also encourage readers to click through to other pages in your blog which is always a good thing. Appropriate link titles should be used to describe what the pages are about.

If you wish to automate this process you can use the SEO Smart Links plugin that will automatically link keywords and phrases in your posts and comments with related posts, pages, categories and tags within your blog.

How to use a Custom Page as a Home Page in WordPress

This is one of the most wanted hacks that users want to know how to accomplish. First you need to learn how to create a custom page. You will need to duplicate your page.php or create a brand new .php file and add the following code at the very top:


<?php /* Template Name: Custom Page */

//code of custom page goes here..

?>

Once you have published this page go to Settings » Reading in your admin panel.

And select your page to be the homepage. Now you have yourself a Custom Home Page.

Modify Excerpt Length and More Tags

WordPress lets you display Excerpts, but up until version 2.9 you could not control the excerpt length. With the following code, you can increase the length from default 55 words to as many words as you like. Open your functions.php file and add the following codes in there:


// Changing excerpt length
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');

// Changing excerpt more
function new_excerpt_more($more) {
return '…';
}
add_filter('excerpt_more', 'new_excerpt_more');

Change the 100 word limit to the count that you desire.

Random Redirect

Allows you to create a link to yourblog.example.com/?random which will redirect someone to a random post on your blog, in a StumbleUpon-like fashion.

Display the most Recent Post from a Specific Category

Did you see sites with a magazine style theme who are displaying posts from a specific category. Sometimes only the most recent post. Well you can do this too easily.


<?php
query_posts('showposts=1&cat=3');
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

<ul><li><?php the_content(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>

Add the above code anywhere you like in the template. Make sure you change the category ID and you can change the number of posts displayed as well if you want.

Display any External RSS Feed in WordPress

Have you seen other bloggers who display their other blog’s feed on their site. You want to do it too for extra promotion and traffic. Well here is the tutorial for you. Simply paste the following code in anywhere in your theme:


<?php include_once(ABSPATH.WPINC.'/feed.php');
$rss = fetch_feed('http://feeds.feedburner.com/wordpressapi');
$maxitems = $rss->get_item_quantity(5);
$rss_items = $rss->get_items(0, $maxitems);
?>
<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href='<?php echo $item->get_permalink(); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo $item->get_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>

Highlight Author’s Comment

Have you ever seen this on blogs where author’s comments are distinguished from other comments? Well this is a simple and easy trick.

First you need to open your style.css in your template folder and add the following:


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

Then you need to open your comments.php which is also located in your themes folder and find the code that looks some what like this:


<li <?php echo $oddcomment; ?>id="comment-<?php comment_ID() ?>"></li>

Replace it with:


<liauthorstyle"; echo $oddcomment; ?>"></li>

Note you must change 1 to the user id of the author. Once you do this, your blog comments will have a different background for the author’s comment compared to the rest.

Change the Default Gravatar Button

The default mystery man is really annoying for most users. Plus if you have one more chance of branding your blog, then why not do it. Changing your default gr-avatar lets you brand your blog more. With this snippet below you can change your default gravatar.

First you need to open your functions.php which is located in your template folder. If you don’t have one then create one and insert the following code:


add_filter( 'avatar_defaults', 'newgravatar' );

function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo('template_directory') . '/images/gravataricon.gif';
$avatar_defaults[$myavatar] = &quot;WordpressAPI&quot;;
return $avatar_defaults;
}

In the code the image is being extracted from the theme directory and it is called gravataricon.gif obviously you will change it to your image name. Where it says WordPressAPI, that is the name of the avatar of how it will show in your admin panel options area.

Head over to your admin panel and click Settings > Discussion and change the icon, and now you have a branded comment area with your logo.

Custom CSS Stylesheet for Individual Posts

There are sites that use custom stylesheet for individual posts. Do you want to know how you can do it also? It is very simple. This is accomplished by the use of Custom Fields.

First you will need to open your header.php and insert this code somewhere in between <head></head> codes.


<?php if (is_single()) {
$customstyle = get_post_meta($post->ID, 'customstyle', true);
if (!empty($customstyle)) { ?>
<style type="text/css">
<?php echo $customstyle; ?>
<style>
<?php }
} ?>

Once you have done that you can add a custom field in each post with the name customstyle and add the css codes in there.

For example if you want the a certain image to have border you can add:


#coolimageclass{border: 5px solid #ccc;}

Use the format above and you now have custom CSS for your single posts.

Display Latest Sticky Posts in WordPress

Assuming that you have already created a custom page template and/or already have The Loop ready, paste the following code before the loop.


<?php
/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );

/* Sort the stickies with the newest ones at the top */
rsort( $sticky );

/* Get the 5 newest stickies (change 5 for a different number) */
$sticky = array_slice( $sticky, 0, 5 );

/* Query sticky posts */
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );
?>

Image Caption

Extracts the title or alt attribute from images within your blog post and generates a neat caption directly underneath those images. Supports custom CSS styling for captions.

Display Most Recent Comments with Gravatars

Have you seen sites that display most recent comments in their sidebar with user gravatars. Well this can be done easily with these codes. Simply paste the following code anywhere you want to display the most recent comments.


<?php
$query = "SELECT * from $wpdb->comments WHERE comment_approved= '1'
ORDER BY comment_date DESC LIMIT 0 ,5";
$comments = $wpdb->get_results($query);

if ($comments) {
echo '<ul>';
foreach ($comments as $comment) {
$url = '<a href="'. get_permalink($comment->comment_post_ID).'#comment-'.$comment->comment_ID .'" title="'.$comment->comment_author .' | '.get_the_title($comment->comment_post_ID).'">';
echo '<li>';
echo '<div>';
echo $url;
echo get_avatar( $comment->comment_author_email, $img_w);
echo '</a></div>';

echo '<div>Par: ';
echo $url;
echo $comment->comment_author;
echo '</a></div>';
echo '</li>';
}
echo '</ul>';
}
?>

Display Different Social Media Submit Buttons

Many if not all blogs has some type of social media integration on their site. Most sites though have different social media sites button on their single pages, so they can get more votes.

Delete Posts Revisions from Your Database

Delete Batches of Post Revisions

WordPress has a lot of good features and one of them is Post Revisions. This was included in WordPress 2.6, even though this is a good feature, it can cause some problems. One of them is increase the size of your database. Depending on how long it takes you to write a post, you might have as many as fifty post revisions. Now you can manually delete them, or you can run a simple query which we will show you in this post and get rid of all these useless revisions.

First thing you need to do is login to your phpMyAdmin and select your WordPress Database.

Click on the SQL Button and enter the following query:


DELETE FROM wp_posts WHERE post_type = "revision";

In this code basically we looked up a table wp_posts and removed every post that had a post_type revision associated with it. Now depending on the size of your database, this may save you a lot of space.

you also use the wp-optimize wordpress plugin which is also very nice plugin.

Show Contact form

Many people use the contact us page with wordpress plugin but I will suggest not to use the wordpress plugin for contact form.

Check following article.

https://purabtech.in/2010/11/26/create-contact-page-wihout-wordpress-plugin/

Show author Information

Many people interested to read about author information in post. Use the following article for showing author information.

https://purabtech.in/2011/01/24/show-author-information-wordpress-post/

Hide WordPress Dashboard Login Errors

For prevent to hackers you should hide the login errors from hackers. For that use following article.

https://purabtech.in/2011/01/03/hide-wordpress-dashboard-login-errors/

I am still trying put more tricks and tutorials about wordpress in this article.

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.