8 Simple WordPress Developers Tips & Tricks To Improve Your Site Significantly

8 Simple WordPress Developers Tips & Tricks To Improve Your Site Significantly

WordPress is a powerful and popular blog medium for most web users. It’s comprehensive yet easy for you to change the appearance of your theme. Not only that, with increasing tons of Plug-Ins and constant enhancement of WordPress version, it can also help you improve the functionality and efficiency of your site.

When you need to get something special, you can write functions or snippets of code to help you get your work done. In WordPress, fine tuning is a very important aspect to customize your blog into a incredibly powerful site.

WordPress Tips & Tricks

Below are 8 simple WordPress Developers Tips And Tricks that I’ve put together which can help you speed up some of your work processes and make your blog even more powerful than it is right now.

How To Remove Tooltip Box From Wp_List_Page?

Sometime, it’s nice not to have the tooltip box appearing when user hover over the list of links displayed by wp_list_pages.

The Solution:

  1. Open the file that you place your wp_list_pages.
  2. Look at the code below to modify it.
<?php
    $pages= wp_list_pages('title_li=&sort_column=ID');
    $pages= preg_replace('/title=\"(.*?)\"/','',$pages);
    echo $pages;
?>

The Explanation:
By using preg_replace, it’ll looks for title tag inside the variable we passed in from wp_list_pages and replace it with an empty string.

How Do You Automatically Insert Content At The Bottom Of Each WordPress Post?

When you are repeatedly adding the same content into every single page of each bottom post, it’s not only time consuming and also cumbersome. Why not make your chore easier by having the content automatically insert into each post for you? Let say, we only want this content to be visible on the Single page only.

The Solution:

  1. Open up functions.php inside your WordPress themes folder.
  2. Copy and paste the code below and save.
<?php
function postFooter($footernote) {
    if(is_single()) {
        $footernote .= "<div class='subscribe'>";
        $footernote .= "<h3>Do you enjoy this post?</h4>";
        $footernote .= "<p>Subscribe to our <a href='http://www.onextrapixel.com/feed/'>OXP RSS Feed</a>.</p>";
        $footernote .= "</div>";
    }
    return $footernote;
}
add_filter ('the_content', 'postFooter');
?>

The Explanation:
We’ll create a function here to take care of this content insertion by applying this filter to the_content. What this function does is, it’ll take the content of each post and run a check. If it is on Single post, then it’ll return the following content inside $footernote at the footer of each post. You can also try changing is_single() to is_feed() if you want certain content to appear on at the footer of your post feed.

How To Change WordPress Default Excerpt […] ?

If you only want to show a excerpt for each post on your home page of your site, you will notice [...] appear by default. So how can you change it to something you prefer, like Continue Reading.

The Solution:

  1. Open up functions.php inside your WordPress themes folder.
  2. Copy and paste the code below and save.
<?php
function replace_excerpt($content) { 
	return str_replace('[...]', '<br /><a href="'. get_permalink() .'">Continue Reading &raquo;</a>', $content); 
} 
add_filter('the_excerpt', 'replace_excerpt');
?>

The Explanation:
By using str_replace, we can replace the string [...] with another string of content you prefer, in this case is Continue Reading with a link to the post itself. After which, we will add the filter to the_excerpt.

How To Display WordPress Single Page For Different Category?

If you want to have a different design or layout single page for different category, you can achieve it with the follow codes.

The Solution:

  1. Open up Single.php inside your WordPress themes folder.
  2. Copy and paste the code below and save.
  3. Put default design or layout for single page in single2.php
  4. Put other categories design or layout for a single page in single1.php
<?php
if (in_category('1')|| in_category ('2')) {
    include(TEMPLATEPATH . '/single1.php');
} else {
    include(TEMPLATEPATH . '/single2.php');
}
?>

The Explanation:
Inside single.php, it will check whether the post is under which category. If it falls in the category that is listed, it will include single1.php file. If not, by default it will include single2.php.

How To Automatically Retrieve The First Image Of The Post And Display at Homepage?

If you are building a magazine style WordPress site. It’s very common that you might want to display an image of the post at the home page. So how can you automatically retrieve the first image of the post for the homepage?

The Solution:

  1. Open up functions.php inside your WordPress themes folder.
  2. Copy and paste the code below and save.

Part 1

<?php
function first_post_image() {
    global $post;
    $imgfirst = '';
 
    $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    $imgfirst = $matches [1][0];

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

Part 2
Now, open up index.php in your WordPress theme folder. Insert the following code to place the first image of your post at the area you want at the homepage.

<img src="<?php echo first_image_post(); ?>" alt="<?php the_title(); ?>" />

The Explanation:
By using preg_match_all, it scans through the each individual post for all the images URL and them pass it as an array to $matches. So by using $matches [1][0] we can retrieve the first image URL for each post.

Now, with the function ready, you can display the first image anywhere in index.php with part 2 of the code.

How To Insert Ads In Your RSS Feed

You can open up more advertising slots for your site by allowing sponsor to buy the ads slot at the bottom of your RSS Feed.

The Solution:

  1. Open up functions.php inside your wordpress themes folder.
  2. Copy and paste the code below and save.
<?php
function rssAds ($content) {
    if(is_feed()){
        $content = $content.'<hr />This Post Was Brought To You By <a href="http://www.onextrapixel.com">Onextrapixel - Showcasing Web Treats without Hitch</a><hr />';
    }
    return $content;
}
add_filter('the_content', 'rssAds');
?>

The Explanation:
If the post is being retrieve, it will check whether if it a home page, single page or feed. If it’s a feed, then the content in $content variable will show.

How To Have Different Design For Different WordPress Category Page

It’s another common tweak that you might interested. Here, how you can have different page design for certain categories when you are using WordPress as your content management system.

The Solution:

  1. Open up category.php inside your WordPress themes folder.
  2. Copy and paste the code below and save.
<?php
if (is_category('1') || is_category('2')) { 
	include(TEMPLATEPATH . '/post1category.php');
}  else {
	include(TEMPLATEPATH . '/post2category.php');
} 
?>

The Explanation:
Again, it’s very similar as the different design for single page. First, it’ll check whether if the category the user select fall on those he define, if not it will display the default category design or layout.

How To Remove Curly Quotes In WordPress Posts & Comments

Have you wonder that even if you copy and paste the PHP code with exact quotation and apostrophe marks into WordPress editor, it’s still causing errors. You can change the curly quotes to the normal straight quotes in your post or comment with the following codes.

The Solution:

  1. Open up functions.php inside your WordPress themes folder.
  2. Copy and paste the code below and save.

Remove Curly Quotes In Posts

<?php remove_filter('the_content', 'wptexturize'); ?>

Remove Curly Quotes In Comments

<?php remove_filter('comment_text', 'wptexturize'); ?>

The Explanation:
The functions above will remove the filter that hook to either the the_content or comment_text.

Conclusion

What I’ve just shared above with you are 8 Simple Quick WordPress Developers Tips & Tricks that I used frequently. There are tons of other useful WordPress Tips & Tricks out there, just Googled for them and you’ll be amazed what WordPress can do for you.

Have any other great WordPress tricks, hacks or tips? Feel free to share with us here.

Comments

    • Marc,
    • June 11, 2009
    / Reply

    Thanks for this list.

      • Terrance,
      • June 18, 2009
      / Reply

      You’re welcome!

  1. / Reply

    very helpful tips, thanks a lot..

  2. / Reply

    thats great but how do you put a seperater image between the page buttons?

    I would like that image between each button as a seperater

  3. / Reply

    my code didn’t show up. please see this site http://www.hivdate.net, I have black dots showing up instead of an image and would like an image to seperate.
    Thanks.

      • Terrance,
      • October 1, 2009
      / Reply

      Best try using list-style: none; for your li.

      if not apply list-style:none; to your .hMenu selector.

      Cheers!

    • Krinkle,
    • November 6, 2009
    / Reply

    Thanks for this great overview !

    Just a small note:
    “How To (..) Different WordPress Category Page” is an unnessecary hack. WordPress does that built-in !

    category-news.php or category-2.php automaticly is used by WordPress for a certain category. No need to hack :)

    See codex.wordpress.org/Category_Templates#What_Template_File_is_Used.3F
    and:
    codex.wordpress.org/Template_Hierarchy#Visual_Overview

  4. / Reply

    Thanks, a good list. And I was looking for an easy fix to the excerpt problem the other day :)

  5. / Reply

    Nice list. Great post as always.

    • Feby,
    • November 18, 2011
    / Reply

    Thanks a lot for the tips and tricks

Leave a Reply

Your email address will not be published. Required fields are marked *

Deals

Iconfinder Coupon Code and Review

Iconfinder offers over 1.5 million beautiful icons for creative professionals to use in websites, apps, and printed publications. Whatever your project, you’re sure to find an icon or icon…

WP Engine Coupon

Considered by many to be the best managed hosting for WordPress out there, WP Engine offers superior technology and customer support in order to keep your WordPress sites secure…

InMotion Hosting Coupon Code

InMotion Hosting has been a top rated CNET hosting company for over 14 years so you know you’ll be getting good service and won’t be risking your hosting company…

SiteGround Coupon: 60% OFF

SiteGround offers a number of hosting solutions and services for including shared hosting, cloud hosting, dedicated servers, reseller hosting, enterprise hosting, and WordPress and Joomla specific hosting.