Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

25+ Extremely Useful Tricks for the WordPress Functions File

Last updated on by
Follow WPBeginner on YouTube
25+ Extremely Useful Tricks for the WordPress Functions File

In your WordPress theme folder, there lays the most powerful theme file known as functions.php. As the name suggests, this file adds unique functions to your WordPress installation. This file works just like a plugin within your theme. So you can modify/override WordPress core features without editing any core file. If used correctly, this file can do wonders for your WordPress site. It also speeds up development because you can have all the codes at one place. In this article, we will share some of the most incredible and most wanted tricks for the WordPress functions.php file.

Note: This article is targeted for WordPress theme developers. You may need have some PHP knowledge for some hacks.

Duh Moments: All codes in this article will be added to the functions.php theme file.

1. Add Google Analytics

Simply paste the code below and insert your Google Analytics where it says paste your Google Analytics. You can paste the code once in your functions.php file and never have to worry about it again. We are adding an action to the wp_footer, so it will automatically insert adsense codes wherever on all pages you have the wp_footer string.

add_action('wp_footer', 'add_googleanalytics');
function add_googleanalytics() { ?>
// Paste your Google Analytics code from Step 6 here
<?php } ?>

For more details: Beginner’s Guide to Installing Google Analytics in WordPress

2. Add a Favicon to your Blog

Every blog deserves to have its own identity. You can add this identity by adding the favicon code in your header.php file, or you can make it easier for yourself by simply adding the following code in your functions.php file.

// add a favicon to your
function blog_favicon() {
echo '<link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('wpurl').'" />';
add_action('wp_head', 'blog_favicon');

Now whenever you are developing the theme, just upload the .ico file in the root folder where the blog is uploaded. You can also modify the file destination if you like. Often theme developers forget to change the URL of the favicon. This can eliminate another worry.

Source: Digging into WordPress

3. Remove WordPress Version Number

You should always encourage your clients to upgrade to the latest version, so you don’t have this problem. But if you are working with a client that does not want to upgrade, then it is essential that you remove your WordPress version number from your WordPress header, RSS feeds, and all other locations. To do this, add the following code:

function wpbeginner_remove_version() {
return '';
add_filter('the_generator', 'wpbeginner_remove_version');

Source: The Right Way to Remove WordPress Version Number

4. Add a Custom Dashboard Logo

When creating themes for a client, you can use this as one of the perks to the theme. All you have to do is paste the following code below:

    //hook the administrative header output
    add_action('admin_head', 'my_custom_logo');

    function my_custom_logo() {
    echo '
    <style type="text/css">
    #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.gif) !important; }


Custom Dashboard Logo in WordPress

Source: Jacob Goldman’s Article on Smashing Magazine

5. Change the Footer in WordPress Admin Panel

You can change the footer of your Free or Custom WordPress themes by adding the necessary links. Simply paste the following code:

    function remove_footer_admin () {
    echo 'Fueled by <a href="" target="_blank">WordPress</a> | Designed by <a href="" target="_blank">Uzzz Productions</a> | WordPress Tutorials: <a href="" target="_blank">WPBeginner</a></p>';

    add_filter('admin_footer_text', 'remove_footer_admin');


Custom WordPress Admin Footer

Source: WPRecipes

6. Add Custom Dashboard Widgets in WordPress

You probably have seen widgets that numerous plugins and themes add in the WordPress dashboard. As a theme developer, you can add one yourself by pasting the following codes:

    add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');

    function my_custom_dashboard_widgets() {
    global $wp_meta_boxes;

    wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'custom_dashboard_help');

    function custom_dashboard_help() {
    echo '<p>Welcome to Custom Blog Theme! Need help? Contact the developer <a href="">here</a>. For WordPress Tutorials visit: <a href="" target="_blank">WPBeginner</a></p>';

Remember to change the email and add any other information you want. Result would look something like this:

Custom Dashboard Widgets in WordPress

Source: Jake Goldman’s Article at Smashing Magazine

7. Change the Default Gravatar in WordPress

Have you seen the default Mystery man avatar on blogs? Why waste the branding opportunity for your clients? You can replace the mystery man with a custom branded gravatar for your clients to give their site a unique touch. All you have to do is paste the following codes:

    add_filter( 'avatar_defaults', 'newgravatar' );

    function newgravatar ($avatar_defaults) {
    $myavatar = get_bloginfo('template_directory') . '/images/gravatar.gif';
    $avatar_defaults[$myavatar] = "WPBeginner";
    return $avatar_defaults;

Don’t forget to upload a custom image to your theme’s image folder. Also change the name of the gravatar to their brand name. Once you upload the image and the functions, then visit: WP-Admin » Settings » Discussion

Custom Gravatar in WordPress

Your gravatar will show up as one of the options.

Source: How to Change the Default Gravatar in WordPress

8. Dynamic Copyright Date in WordPress Footer

Often you will come across sites with outdated copyright dates. Some sites show the current year as their copyright date. Both of these are annoying, and it shows that the site designer was lazy. In order to give your users a little background info about your site, you should display the copyright date as such: © 2006 – 2010. We can do this by simply pasting the following code:

function comicpress_copyright() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
post_status = 'publish'
$output = '';
if($copyright_dates) {
$copyright = "&copy; " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= '-' . $copyright_dates[0]->lastdate;
$output = $copyright;
return $output;

Once you add this function, then open your footer.php file and add the following code wherever you like to display the dynamic copyright date:

<?php echo comicpress_copyright(); ?>

This function looks for the date of your first post, and the date of your last post. It then echos the years wherever you call the function.

Source: @frumph of ComicPress Theme (How to Add a Dynamic Copyright Date in WordPress)

9. Rewrite Guest Author’s Name with Custom Fields

Now many blogs are publishing other authors also known as guest authors. A lot of these guest authors are one time writers. In this scenario, it is not feasible to create user accounts for them. This trick will let you replace the author name to guest author with the use of a custom field. Simply paste the code below:

    add_filter( 'the_author', 'guest_author_name' );
    add_filter( 'get_the_author_display_name', 'guest_author_name' );

    function guest_author_name( $name ) {
    global $post;

    $author = get_post_meta( $post->ID, 'guest-author', true );

    if ( $author )
    $name = $author;

    return $name;

Now every time there is a guest post, simply add the custom field guest-author.

Custom Fields - Guest Author

Source: Guest Authors in WordPress

10. Enable Post Thumbnails in WordPress

Starting from WordPress 2.9, you can use the default built-in Thumbnails feature in your themes. To do this, you must enable the post thumbnails inside your functions.php file. Paste the code below:

add_theme_support( 'post-thumbnails' );

Then simply place the following code inside your loop where you want to display the thumbnail:

<?php the_post_thumbnail(); ?>

You can follow the Video Tutorial here:

Source: How to Add Post Thumbnails in WordPress

11. Custom Navigation Menus in WordPress 3.0

WordPress 3.0 comes with an awesome menu management system which theme developers can utilize to their advantage. If you want to give your users the option to use this core feature, then add the following function:

add_theme_support( 'menus' );

Then you can call this function anywhere you like in your template file by pasting the code below:

<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>

Additional Resource: WordPress Codex

12. Remove Default Author Profile Fields in WordPress

If you are creating a site where your client will be adding user information, then make the interface easier for them. One of the ways you can do this is by removing the unwanted fields such as AIM, Yahoo IM, Jabber etc. Simply paste the following code to remove these fields:


    function hide_profile_fields( $contactmethods ) {
    return $contactmethods;

Source: Strangework

13. Add Author Profile Fields

If you want to create a more versatile author page, then you would need to add additional fields to the author profile. The code below will show you how to add additional twitter and facebook fields, but you can use it to add any other field that you like.

    function my_new_contactmethods( $contactmethods ) {
    // Add Twitter
    $contactmethods['twitter'] = 'Twitter';
    //add Facebook
    $contactmethods['facebook'] = 'Facebook';

    return $contactmethods;

The function above will add something like this:

Custom Author Profile Fields

You can then call the fields in your author.php template by adding the following code:

<?php echo $curauth->twitter; ?>

** This tutorial will work only with versions 2.9+

Source: Yoast

14. Register Sidebar Widgets

This is one of the most used ones and many developers already know about this. But it deserves to be in this list for those who don’t know. Paste the following code in your functions.php file:

if ( function_exists('register_sidebar') )
'before_widget' => '<li class="widget">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h3>',
'before_widget' => '<li class="widget">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h3>',

The code above will register two sidebars. You can register as many as you need. To display the sidebar in your theme, simply paste the code where you like:

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('MiddleSidebar') ) : ?>
    <!–Default sidebar info goes here–>

    <?php endif; ?>

Do the same for the other sidebars. Note sidebars does not have to be in your sidebar.php file.

Additional Resource: WordPress Codex

15. Manipulate Your RSS Footer

Have you seen blogs that adds their advertisement in their RSS Feeds below each post. You can accomplish that easily with a simple function. Paste the following codes below:

function wpbeginner_postrss($content) {
$content = 'This post was written by Syed Balkhi '.$content.'Check out WPBeginner';
return $content;
add_filter('the_excerpt_rss', 'wpbeginner_postrss');
add_filter('the_content', 'wpbeginner_postrss');

We are calling a function wpbeginner_postrss to add in each post a content before the post saying This Post was written by Syed Balkhi and after the content Check out WPBeginner. But we add the function if(is_feed), so it will only be displayed in RSS Feeds.

You can do this with a plugin called RSS Footer by Joost De Valk.

16. Add Post Thumbnails to Your RSS Feeds

The post thumbnail feature is usually only displayed within your site design, but you can extend that functionality to your RSS feed with a simple function. Paste the codes below:

function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) .
'</p>' . get_the_content();
return $content;
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');

Feel free to style this however you like.

Source: Dave Redfern

17. Enable Threaded Comments in WordPress

Threaded comments is one of the best feature WordPress has. You can enable the threaded comments by visiting your wp-admin settings > discussion area, but you still need to add the JavaScript to your header file to make commenting easier. When developing themes, you want it to be as clean as possible, so stop cluttering your header.php file. Simply add the following function:

// enable threaded comments
function enable_threaded_comments(){
if (!is_admin()) {
if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1))
add_action('get_header', 'enable_threaded_comments');

Source: Digging into WordPress

18. Remove Error Message on the Login Page

When you enter a wrong password or an invalid username, you get an error message in the login page. So if a hacker gets one thing right, the error message will help them identify that. You can stop helping the hacker by adding the following function:

add_filter('login_errors',create_function('$a', "return null;"));

Now when there is an error, you will see an empty box:

Remove Error Message on the Login Page

Not recommended for sites with multiple authors.

19. Disable Search in WordPress

When using WordPress as a CMS, sometimes the search feature becomes unnecessary. You can remove the search bar from the design, but the functionality still remains. You can add the following function and disable the search function:

    function fb_filter_query( $query, $error = true ) {

    if ( is_search() ) {
    $query->is_search = false;
    $query->query_vars[s] = false;
    $query->query[s] = false;

    // to error
    if ( $error == true )
    $query->is_404 = true;

    add_action( 'parse_query', 'fb_filter_query' );
    add_filter( 'get_search_form', create_function( '$a', "return null;" ) );

Source: WPEngineer

20. Enable Adsense Shortcode

Adsense is one of the most popular ad elements used by bloggers. Theme designers can place the adsense box in one spot which limits the users. If you want to give your client the ability to add the adsense anywhere, then you can create a shortcode for the adsense using this function:

    function showads() {
    return '<div id="adsense"><script type="text/javascript"><!–
    google_ad_client = "pub-XXXXXXXXXXXXXX";
    google_ad_slot = "4668915978";
    google_ad_width = 468;
    google_ad_height = 60;

    <script type="text/javascript"

    add_shortcode('adsense', 'showads');

Source: Jean-Baptiste Jung’s article on Smashing Magazine

21. Change Your WordPress Feed Links without .htaccess

If you setup feedburner for your blog, then you should redirect your WordPress feeds to the feedburner feed links. This way you will not lose any subscriber. Normally users do it with a plugin, but you can do it for your client with this function:

    function custom_feed_link($output, $feed) {

    $feed_url = '';

    $feed_array = array('rss' => $feed_url, 'rss2' => $feed_url, 'atom' => $feed_url, 'rdf' => $feed_url, 'comments_rss2' => '');
    $feed_array[$feed] = $feed_url;
    $output = $feed_array[$feed];

    return $output;

    function other_feed_links($link) {

    $link = '';
    return $link;

    //Add our functions to the specific filters
    add_filter('feed_link','custom_feed_link', 1, 2);
    add_filter('category_feed_link', 'other_feed_links');
    add_filter('author_feed_link', 'other_feed_links');

Source: Justin Tadlock

22. Enable a Paypal Donate Shortcode

There are times when you are writing a post, and you get an opportunity to plugin your donate link. This function makes it easy for you by enabling a shortcode which you can use in your posts at any given time. Paste the code below:

    function donate_shortcode( $atts ) {
    'text' => 'Make a donation',
    'account' => 'REPLACE ME',
    'for' => '',
    ), $atts));

    global $post;

    if (!$for) $for = str_replace(" "," ",$post->post_title);

    return '<a class="donateLink" href="'.$account.'&item_name=Donation for '.$for.'">'.$text.'</a>';

    add_shortcode('donate', 'donate_shortcode');

Make sure to change your account information and the text if you like.

Source: ThemeForest

23. Control When Your Posts are Available via RSS

All bloggers make errors that we catch after we publish the post. Sometimes even within the next minute or two. That is why it is best that we delay our posts to be published on the RSS by 5-10 minutes. You can do that by adding this function:

    function publish_later_on_feed($where) {
    global $wpdb;

    if ( is_feed() ) {
    // timestamp in WP-format
    $now = gmdate(‘Y-m-d H:i:s’);

    // value for wait; + device
    $wait = ‘10′; // integer


    // add SQL-sytax to default $where
    $where .= ” AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, ‘$now’) > $wait “;
    return $where;

    add_filter(‘posts_where’, ‘publish_later_on_feed’);

This code is adding a 10 minute delay on your post being shown on the RSS Feeds, you can change it by changing the number 10 to as many minutes as you like.

24. Customize Excerpt More […]

There is an annoying […] added at the end of each excerpt. You can change this to anything you like with a simple function:

    // custom excerpt ellipses for 2.9
    function custom_excerpt_more($more) {
    return '…';
    add_filter('excerpt_more', 'custom_excerpt_more');

    /* custom excerpt ellipses for 2.8-
    function custom_excerpt_more($excerpt) {
    return str_replace('[...]', '…', $excerpt);
    add_filter('wp_trim_excerpt', 'custom_excerpt_more');

Source: Digging into WordPress

25. Custom Excerpt Length

By default the excerpt length is capped at 55 words. Many theme designers like to have the flexibility that is why WordPress lets you customize the excerpt length with this function:

function new_excerpt_length($length) {
return 100;
add_filter('excerpt_length', 'new_excerpt_length');

Change 100 to the length you like.

26. Display the Most Accurate Comment Count

By default, WordPress counts trackbacks, and pings as comments. This inflates the comment count which looks really bad especially when you are not displaying the trackbacks and pings. To fix the count add the following function:

add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $count ) {
if ( ! is_admin() ) {
global $id;
$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
return count($comments_by_type['comment']);
} else {
return $count;

27. Disable RSS Feeds

For static WordPress sites, you do not need to have an RSS feed option. You can disable the RSS feeds with this function if you want:

    function fb_disable_feed() {
    wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url') .'">homepage</a>!') );

    add_action('do_feed', 'fb_disable_feed', 1);
    add_action('do_feed_rdf', 'fb_disable_feed', 1);
    add_action('do_feed_rss', 'fb_disable_feed', 1);
    add_action('do_feed_rss2', 'fb_disable_feed', 1);
    add_action('do_feed_atom', 'fb_disable_feed', 1);

Source: WPEngineer

28. Display Twitter Followers Count and More

There are widgets that display Twitter followers count, but those are limited and ugly. You can use this function to customize the way your twitter followers count look on your blog. Simply paste the code below:

    function rarst_twitter_user( $username, $field, $display = false ) {
    $interval = 3600;
    $cache = get_option('rarst_twitter_user');
    $url = ''.urlencode($username);

    if ( false == $cache )
    $cache = array();

    // if first time request add placeholder and force update
    if ( !isset( $cache[$username][$field] ) ) {
    $cache[$username][$field] = NULL;
    $cache[$username]['lastcheck'] = 0;

    // if outdated
    if( $cache[$username]['lastcheck'] < (time()-$interval) ) {

    // holds decoded JSON data in memory
    static $memorycache;

    if ( isset($memorycache[$username]) ) {
    $data = $memorycache[$username];
    else {
    $result = wp_remote_retrieve_body(wp_remote_request($url));
    $data = json_decode( $result );
    if ( is_object($data) )
    $memorycache[$username] = $data;

    if ( is_object($data) ) {
    // update all fields, known to be requested
    foreach ($cache[$username] as $key => $value)
    if( isset($data->$key) )
    $cache[$username][$key] = $data->$key;

    $cache[$username]['lastcheck'] = time();
    else {
    $cache[$username]['lastcheck'] = time()+60;

    update_option( 'rarst_twitter_user', $cache );

    if ( false != $display )
    echo $cache[$username][$field];
    return $cache[$username][$field];

Then place the following code where you want to display the count in your theme file:

echo rarst_twitter_user('wpbeginner', 'name').' has '.
rarst_twitter_user('wpbeginner', 'followers_count').' followers after '.
rarst_twitter_user('wpbeginner', 'statuses_count').' updates.';

The above code will display something like this:

WPBeginner has 6127 followers after 1390 updates.

Source: Rarst

This list does not do justice to the power of the functions.php file. Entire theme frameworks are built solely on this one file. You can use it to add custom post types, create theme admin panels, and much more.

Additional Resources

Digging into WordPress – One of the best e-books for WordPress developers. It has some of the best uses of functions.php file.

Go to Any Design / Development related blog and type functions.php in their search to see what you can do with this file. Just on our site, you should be able to find 30+ articles about the uses of functions.php file. Try it for yourself:

Thanks to everyone who contributed in making this post possible on our Facebook Fan Page :) Everyone should join now, so you can help us write the post that you want.

Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

    such a great and useful tricks.. :)

  • Marco

    thank you so much!

  • Webtechideas

    Such a nice list of useful tricks. It will help both plugin and theme developers.

  • ahmed

    In #14, isn’t that a instead of ?

  • Mick O

    Thanks for the helpful article. I really appreciate it. Can you possibly explain why the snippet to add Google analytics (#1) code includes the php declarations. If I have an existing functions.php file that is already defined with , do I need to include the markers again in the snippet? I’m trying to add other customizations into the functions.php and it’s getting hard to keep track.

    • Editorial Staff

      It includes opening php because it is closing PHP tag to allow you to paste plain HTML Google analytics code.

  • Luke Gibson

    The one about the copyright date seems a little OTT when you could simply cut and paste in © 2006- and it would do exactly the same job, just replace 2006 with whatever static start date you wish. Or am I missing something?

    • Editorial Staff

      Yes, you can definitely do that. But if you are releasing this as part of a theme meant for distribution, then you can’t do that.

  • Zeeshan Arshad

    Excellent, I was done with my theme and learning but there was much left. This post saved my day and of course I learnt many things as well.

    Best Wishes!

  • DesignSkew

    In “Add Author Profile Fields”, the function you mentioned to echo is not working.

    • Editorial Staff

      The curauth would only work if it is on author.php file.

  • Mark

    Great set of tools. I immediately copied the guest author function as I saw it and will now disable a clumsy plugin I’ve been using. Do you have a function that will provide the post ID of the item being worked with in the editor? I’m trying to auto fill a form with media attachments for the current post but have only been able to get it to work in a custom meta-box but not in a thickbox . The thickbox returns all the media files for all the posts when I just want the current posts’s attachments.

  • mommyblogger

    Thanks for the great WordPress tips! I was hoping you could help me with an additional one?

    I’d like to prevent my tags/categories from spilling over onto another line by limiting the number of tags/categories that appear in the footer of my individual homepage posts. Is it possible to do this with the “the_excerpt”? I would also like the excerpt to be a “…read more” link and limit the number of characters in it. Here is the code it would need to be added to;

    $tags_list = get_the_tag_list( ”, __( ‘, ‘, ‘mummyblog’ ) ); if ( $tags_list ): ?> <li> <?php printf( __( ‘<span class=”%1$s”>Tagged</span> %2$s’, ‘mummyblog’ ), ‘entry-utility-prep entry-utility-prep-tag-links’, $tags_list ); ?> </li> <?php endif; // End if $tags_list ?>


  • SteveEBoy

    Like all the others have said below – just too good, a massive help for a newbie and very useful for learning too. Great site all round. Thanks.

  • LambrosPower

    one of the best tutorials i read. Many important topics pointed out and for sure i didn’t know most of them since i just started wordpress custom design.

  • Xiaozhuli

    This article is endlessly useful. I bookmarked it and often refer to it when updating my theme or trying to answer a question. Great job!

  • Mohammad Yeasin

    You guys are just awesome. You know what, wpbegineer is the first website for which i have a separate folder in my bookmark menu. Too good for a wp begineer. youe name suits ur personality. lolz. One day i would must do something special for you. Inshallah.
    The only problem i face is related post with thumbnail. your coder are not working. vDont know what to do. Whatever, Keep up the marvelous job. Love the site wpbegineer.

  • AA

    Great post! You obviously know a lot about wordpress coding so I’m hoping you can answer a question. How to you remove the date & time stamp from a wordpress feed-rss? I’ve looked everywhere and can’t find any information on this. I’m working on a wordpress “site” and do not have a use for the dates. I have already removed them from the posts & pages.

    Much thanks in advance!

    • Editorial Staff

      Date is NOT optional for RSS feeds. It is a MUST because that is how posts / articles are organized (reverse chronological order). You can remove the display of dates from the template, but you cannot remove them from the XML.

  • Michele Welch

    Awesome post! Can’t wait to get started on the custom dashboard gravatar! Really exceptional post. :-)

  • Phil

    Great article, I’ve bookmarked it for future reference. Just found wpbeginner by chance what a great resource, thanks!

  • wparena

    it is really good that you compiled all impotent things at one place

  • Mark Welburn

    Good stuff, bookmarked this already. Can see a few of these come to good use more than once. Cheers, Mark.

  • Connor Crosby

    Just a note, be careful when you copy and paste the “end of excerpt” function. It showed a question mark instead of “…” since it was one character. I had to rewrite “…” for it show up.

  • Martin

    Probably the best post about the use of functions.php. Thanks for the tricks and for saving our time.

  • Huw Rowlands

    Wow! Some really handy stuff there!

    Thanks for sharing.

  • mark.

    I would suggest an addendum be made to Tip #3 mentioning the fact that this is not security in any way shape or form, and is definitely not an alternative to upgrading as people should.

    Hiding the version number is only beneficial to those of us who like to keep unnecessary junk out of the HEAD of your HTML document. Outside of that, it serves no purpose and should not be confused with security; to help illustrate that point:

  • helpin

    Could you tell me if I need to add these codes for every theme which my multi site have? Is there any there way which these codes automatically apply to the newly added themes?

    Thanks !

    • Editorial Staff

      You would have to add these to your theme’s functions.php file. So if it is a theme that is available on all networks, then only once. If there are custom themes being used on each network site, then you would have to do it on each….

  • Connor Crosby

    Very nice list. I didn’t know you could do so much with the functions.php file!

  • Andy

    You guys rock!!! Thanks for the awesome post.



  • Jennifer R

    thanks you for these useful tricks

  • Marcelo Torres

    Wow very good! Thanks for sharing ;)

  • tarpontech

    Best Damn WordPress Article I’ve ever stumbled across.

  • ddeja

    Thanks for those tips. Some are new for me. So I will be probably try to use them:)

    Thanks again.

  • Chuck Reynolds

    Since WP3 final release you need to update #11 to

    add_theme_support( ‘menus’ );

    • Editorial Staff

      Fixed thanks :)

  • William

    Thanks for the insightful post. Registering sidebar widgets and customising the excerpt mode is going to be handy. Cheers

  • Kate Mag

    Thanks for sharing extremely useful tricks. I didn’t know few tricks before, i know now!.

  • Adam

    Okay, the dynamic copyright date in the footer is one of the coolest tricks for WordPress I’ve come across. Always hate having to do that each year, but not anymore. Thanks for sharing that one!

  • Susan

    Hi, I am trying to change the default gravatar. The option to choose my new gravatar is showing up however instead of my pic for my gravatar it is showing a broken pic link. I know the path works cause it does when I plug it in to the browser the pic comes up. I have also tried .gif, .png, .jpg and they are all broken. Also it is sized per my theme at 48px X 48px Can you help?

    • Susan

      I finally got it!! Thanks for the awesome post btw.

  • Dave Z

    There are some good suggestions here. Implementation could be improved for a few of them.

    For instance, in #8 – Dynamic Copyright, it would probably be better to call the function during the publish_page and publish_post actions. Then, instead of printing the year to the screen, the value (year range) could be stored in the options table (with update_option()). In the theme, you would do something like: echo get_option( ‘comicpress_copyright’, date( ‘Y’ ) );. This would give the current year as the default date, or your preset range. The advantage here is that you eliminate the constant need to query the database for the years during every page load (since get_option can be configured to load automatically with the rest of the options). WordPress can already be heavy on database queries, no need to add an additional one if it can be avoided!

    #18 – Remove Login Errors is removing -all- login errors, which could be bad because it also omits notices about disabled cookies, etc. A more effective approach would be to have the function return:

    str_replace( array( ‘Invalid username’, ‘Incorrect password’ ), ‘Invalid username or password’, $str );

    This keeps the user informed of potential errors while obfuscating which field the error actually occurred in. One thing to keep in mind is that if the username is correct, WordPress will auto-populate that field in subsequent login attempts. A hacker aware of WordPress operation would then know that the username was indeed valid. You can prevent this by commenting out the appropriate section in the wp-login.php file (lines 529-530 in version 2.9.2)–not ideal, I know, but there are no hooks at that point in the code.

    Nice tips. I like the Post Thumbnails demonstration.

    • Editorial Staff

      Thank you for your tips :) Really appreciate it.

  • Abdullah

    Nice post.. very useful information.

    Thnkx wpbeginner for making us more professional in our field.

    Mohummad Abdullah

  • Zhu

    Thank you for the tips, I already implemented a few (like the custom Gravatar) and they work just fine!

  • Waheed Akhtar

    Great list. Bookmarked for any reference in future

  • Sahus Pilwal

    Thanks for the extremely helpful tips. I wish I could find more extremely useful tricks/hack articles for WordPress!

    Cheers, Sahus

  • patrick andrew adams

    i can’t wait to try a few of these out, pretty new to wp still.

  • graphicbeacon

    slight problem with NO. 14. Widget title starts with a h2 tag and ends with an h3- Wouldnt validate well methinks.

  • Todd Santoro

    here is one for changing the login logo:

    function the_custom_login_logo() {
    echo ‘
    h1 a { background-image:url(‘.get_bloginfo(‘template_directory’).’/images/custom-login-logo.gif) !important; }

    add_action(‘login_head’, ‘the_custom_login_logo’);

    • Todd Santoro

      Make sure you change the single quotes in this code to actuall single quotes as WP strips them in the comments so the PHP code is not executed. Better yet retype it and you will have no problem.


  • Kenton Bell

    I am really impressed with this list, better options than hacking away at the theme files that get lost in upgrades. Thank you.

  • Raoni


    just an update, in item 4. Add a Custom Dashboard Logo, in WordPress 3 the “custom-logo.gif” now is a .png image.

    Great collection!!!!

  • Andris

    That was a very useful post. I just implemented “4. Add a custom Dashboard Logo” to my Website.

  • Todd Santoro

    Great post. I have this in my WP tool box now. It has everything a theme designer would need in one article. Thanks WPBeginner!

  • Jake Goldman

    Great tips. Got a kick out of seeing a few of mine in there. :-) lots of new tips coming soon in my next article!

    • Editorial Staff

      Will keep my eyes open :)

  • Tony

    Finally! I know how to cure the incorrect comment count! Thanks, WPBeginner!

  • DaveK

    Brilliance, I will be putting quite a few of these to good use.

    Congrats on the site guys you go from strength to strength, I usually manage to find something useful here.

    Keep up the good work.