Articles in this series

64 Responses

  1. Chip Bennett
    Chip Bennett December 30, 2010 at 8:35 pm |

    Great writeup, Justin!

    Out of curiosity: why no if ( ! function_exists( 'mytheme_setup_theme' ) ) {} wrapper around the Parent Theme’s mytheme_setup_theme() function, for direct override by Child Themes?

    Reply
  2. Mark McWilliams
    Mark McWilliams December 30, 2010 at 8:44 pm |

    Another GREAT quality article Justin! :) Got to say it was well worth the read, and thanks for that new little bit of knowledge. Maybe I’ll get round to creating a (Child) Theme or that in 2011, we’ll see what happens?

    Reply
  3. Chuck Reynolds
    Chuck Reynolds December 30, 2010 at 9:06 pm |

    Good write-up… I tend to just add stuff at the bottom quite often when I’m rebuilding something… Just cleaned up my personal site’s functions file and I like that setup… reads better and overall is much better.

    Reply
  4. lishijie
    lishijie December 30, 2010 at 10:58 pm |

    I really like your theme, my station is to use your theme, thank you very much to share

    Reply
  5. Brian Krogsgard
    Brian Krogsgard December 30, 2010 at 11:01 pm |

    Thank you. Thank you. Thank you. and Thank you. 1 for each of the 4 tips.

    I’ve been realizing some of my past errors recently, but the prefixes and priorities really make more sense now. Your tutorials are priceless… well, very valuable at least ; )

    Thanks as always.

    Reply
  6. rzepak
    rzepak December 31, 2010 at 5:16 am |

    Show me your functions.php and I’ll tell you who you are :)

    Thanks Justin for great article! I’ll start to clean my themes today.

    Reply
  7. Adam W. Warner
    Adam W. Warner December 31, 2010 at 8:33 am |

    Even though I’m not building themes anymore, I’m always mucking around in the functions.php files of various themes to do add custimizations or one sort or he other.

    Your write has just helped me understand where and how I should be adding my own functions:)

    Thanks Justin, glad to see your still writing!

    Reply
    1. Adam W. Warner
      Adam W. Warner December 31, 2010 at 8:34 am |

      Geez, I guess I need more coffee…sorry for the spelling above :/

      Reply
  8. Jake
    Jake December 31, 2010 at 10:00 am |

    Thanks Justin for this great tip. I’m always excited to read new post from your blog. I know something useful will come out from you! Thanks again!

    Reply
  9. Jamal Mohamed
    Jamal Mohamed December 31, 2010 at 10:16 am |

    Great write-up, Justin.

    I’ve been recently looking into the code of a couple of the so-called premium themes. I felt shocked when I saw how many familiar snippets from the internet were pasted awkwardly into the functions.php file.

    Post thumbnails function was around for more than a year and many leading theme developers still use timthumb.php to resize images and, ironically, they still tell users to insert image URLs in the custom fields when WordPress has post feature image functionality. Maybe these theme developers are only interested to gain fame and fortune without giving much care the quality of their codes.

    …you created a [parent] theme setup function and hooked it to after_setup_theme with a priority of 10 in the previous section (10 is the default, so it’s actually shown in the code).

    Erm… do you mean “10 is the default, so it is NOT actually shown in the code”?

    Reply
  10. Manish Goyal
    Manish Goyal January 1, 2011 at 3:56 am |

    Thanks Justin. I have never go through the function files in detailed. But through this post it’s really very easy to understand about them. Great piece of work here and hope you will recommend some more good stuff. Especially the code’s gives an idea how to handle such a situation.

    Reply
  11. Rami
    Rami January 1, 2011 at 5:04 pm |

    I think the problem is that we don’t have enough tutorial/guides like this one. When theme developers have more guides like this one, they will code their themes properly.

    Reply
    1. Zialingua
      Zialingua January 17, 2011 at 3:33 pm |

      Rami, i cannot agree more with you.
      Seriously WP has to give proper guidelines on how to use WP for theme and plug-in developers to produce correct code.
      At the moment it is a jungle where one has to spend hours or days to find things.
      Seriously, WP core developers cannot claim that people are able to read their minds to understand how to code themes and plug-ins without telling how to use this WP application.

      Reply
  12. dronix
    dronix January 2, 2011 at 10:48 pm |

    Would you recommend to “always” specify the priority number when using hooks? I’ve never run into a case where I’ve had to specify the priority and would like to know what would be the best practice.

    Reply
  13. Ralf Hortt
    Ralf Hortt January 4, 2011 at 4:46 am |

    I prefer to write the hook below the function i.e:

    function myhook(){
    	// Does something
    }
    add_action( 'ahook','myhook' );

    Which way is better ? I do it because I fear that someday the add_action function will check if the callback is a function.

    Reply
  14. Kaiser
    Kaiser January 6, 2011 at 10:14 pm |

    Other things every theme/plugin author should know/do:
    http://wordpress.stackexchange.com/questions/715/

    And yes: (Imo) Everything should be hooked or filtered in wp.

    Reply
  15. Aws
    Aws January 7, 2011 at 12:12 pm |

    that is great thanks Justin :)

    Reply
  16. Nick Plekhanov
    Nick Plekhanov January 7, 2011 at 2:37 pm |

    Another GREAT quality article Justin!

    My BIG request: can you publish some tuts on:
    1. Creating very first real-life plugin from scratch.
    2. Creating a simple template from very scratch.

    ..both using high-top coding standards and practices with all theme /plugin files.

    HUGE THANKS!

    Reply
  17. Kishore Mylavarapu
    Kishore Mylavarapu January 10, 2011 at 11:52 pm |

    Great tutorial.Really simple to understand.

    Reply
  18. Robert Popovic
    Robert Popovic January 11, 2011 at 9:44 pm |

    When developing some more complex custom themes, I like to split out groups of custom functions and classes used in functions.php to several include files located in a theme subfolder. Just like the hybrid and your other themes do it.

    For example, I often have a bunch of utility functions, then the theme options and admin stuff, etc… splitting them out allows me to reuse them easily in the next project/theme.

    Reply
  19. WordPress theme function files
    WordPress theme function files January 18, 2011 at 10:38 pm |
  20. Marlon
    Marlon January 24, 2011 at 1:04 pm |

    Awesome! Tanks a lot

    Reply
  21. How to Load WordPress Javascript and Stylesheets Using wp_enqeue_script and wp_enqueue_style | Mark Wilkinson on WordPress
  22. Hybrid theme version 0.9
    Hybrid theme version 0.9 March 7, 2011 at 11:20 pm |
  23. Michael Hall
    Michael Hall March 16, 2011 at 2:04 pm |

    first time reader and i’ve already gobbled up about 4 articles, gonna grab a copy of your book in a few days too.

    thanks for the great info and clarity.

    i especially love reading about cleaning up code, and only very recently discovered wp hooks after reading sitepoints wordpress book

    Reply
  24. Sarah
    Sarah March 27, 2011 at 6:48 am |

    Thank you for this. Exactly what I needed to sort my code :)

    Question: would adding

    load_theme_textdomain(‘my-theme’, TEMPLATEPATH . ‘/languages’);

    be appropriate in the same function?

    Reply
  25. Jason
    Jason April 20, 2011 at 3:39 am |

    This post is seriously so valuable. I can’t thank you enough for taking the time to go into so munch detail about including functions in our themes.

    Reply
  26. 7up
    7up May 12, 2011 at 7:00 pm |

    Understanding how child themes are related to the parent themes is the most important info I got today.
    Thanks.

    Reply
  27. Janine
    Janine May 18, 2011 at 6:12 am |

    Just to echo all the previous comments and thank you for taking the time to put articles like this together.
    This sort of info should really be in the official docs. I look up individual functions all the time in the codex and in the example code given, I don’t recall seeing the example wrapped in a function and wired up with a hook, or they don’t mention which functionality should be matched with which hook.
    This encourages bad development practices without developers realising that they are not doing things the right way.

    Reply
  28. Javier
    Javier August 23, 2011 at 10:48 am |

    Hey! First of all, thanks for an awesome post. Truly moving.

    I’m trying to get my comments styling function inside an add action line. What hook do you think it would be appropriate to put it into? Should it be on the same ‘after_setup_theme’ or is there a better suit?

    Reply
  29. Denis
    Denis August 25, 2011 at 4:56 pm |

    Thank for a nice tutorial on functions.php. I am trying to clean my header via remove_action( ‘wp_head’, ‘parent_post_rel_link’, 10, 0 ); Should I use After_setup_theme hook for that? Thank you in advance.

    Reply
  30. Using remove_action in a Wordpress child theme | Marcus Nyberg
  31. Dear theme developers, this is how you add scripts in WordPress themes | WPCandy
  32. Create a child theme functions file | Twelve NMS509.com
  33. How to Add target=”blank” to all links
  34. Create a child theme functions file - Laura Collins
  35. Create a child theme functions file (+2) | TEN50nineTEN50nine
  36. Creating a child theme functions file (2 points) | NMS 509 Fall 2012NMS 509 Fall 2012
  37. Create a child theme functions file | Run 2012Run 2012
  38. Create a child theme functions file (2 points) | 13 Thirteen NMS509.com13 Thirteen NMS509.com
  39. Add a custom field and display it on single post pages (+5) and style (+2) | TEN50nineTEN50nine
  40. Create a child theme functions file (2 Points) | The "Oh So Customized" BlogThe "Oh So Customized" Blog
  41. WordPress: Necessary Reading | Tom J Nowell
  42. BDW @ Night: WordPress Intro - session 1 | hank is me
  43. Using Custom Fields and Custom Post Types in Wordpress
  44. My Journey into Web Design - aXtran
  45. VIDEO'EX » WebTekNeq's » WebTekNeq's
  46. Ted
    Ted May 6, 2013 at 9:45 pm |

    As a newbie to Wordpress, I learned a lot just from reading this post. I recently developed a small site that relies a lot on Gravity Forms and their user registration add on. Your members plugin is their go-to solution for solid content management. Gravity Forms is great and your knowledge of Wordpress is clear from your plugins and writing.

    I only wish that you had made the login widget that comes with “members” so that it would enable “register or login” for the unregistered or un-logged in user and change to “logout” when a registered user is logged in. In fact the whole user registration and login UX of wordpress could benefit from your attention. Thanks for your good work either way. It’s much appreciated.

    Reply

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.