Podcast Episode

108 – The Dangers of the functions.php File

Announcements

Advanced WordPress Developers Course
– Last week in January
– Take your developer skills to a whole new level

Tools / Plugins

oEmbeds http://codex.wordpress.org/Embeds
One of the great features in WordPress that is rarely mentioned is oEmbeds. This give the ability for WordPress users to simply paste a link (the main URL) to their YouTube video (and other services) directly into their visual editor. This saves a blog / website owner from learning how to find the embed code, format the application to be the correct size, then switch to the HTML editor to paste in the code.

Main Topic

Dave Clements (http://doitwithwp.com/)
Some of the questions that were covered on today’s episode:
– Tell me a little about yourself. Who is Dave Clements?
– How long have you been using WordPress?
– Why do you cringe when I mention adding code to your functions.php file?
– Where should I be putting this code?
– Is it hard to create my own plugins?
– Can I put several snippets of code in one plugin?
– How can I make sure that some the website owner doesn’t accidentally turn off my plugin or remove it

Call To Action

    • forresttanaka Reply

      Interesting conversation; so interesting I listened to it twice back-to-back! I was wondering though, this concept of creating custom plugins instead of adding to functions.php only applies if you’re modifying someone else’s theme though; is that right? If you’re making a custom theme from scratch or making a child theme, then I wouldn’t think this applies because you’re never updating the theme using the WP update mechanism.

      Dec 28, 2012
      • daclements Reply

        @forresttanaka Not really: when it comes time to change your theme one day, you’ll want all that custom functionality in one place, that isn’t going to die with your theme. It’s also good practice to do it “the correct way” than to perpetuate bad habits. It’s no more difficult doing it the right way, so that should be your default 🙂

        Dec 28, 2012
        • forresttanaka Reply

          @daclements  Thanks for the replies, guys! I see what you mean, and probably should have seen that myself since I’m in the process of making a new theme for my own site right now, and will toss my old one when it’s done. Cool stuff!

          Dec 28, 2012
      • dhartzler10 Reply

        @forresttanaka What Dave said 🙂  Basically, if you put your custom code in the functions.php file and you changed your theme, then you would have to copy all the custom code to your next theme’s functions.php file. By creating your own plugin,  then you can change themes with less hassle.

        Dec 28, 2012
    • daclements Reply

      Not really: when it comes time to change your theme one day, you’ll want all that custom functionality in one place, that isn’t going to die with your theme. It’s also good practice to do it “the correct way” than to perpetuate bad habits. It’s no more difficult doing it the right way, so that should be your default 🙂

      Dec 28, 2012
    • Geocaching Studio Reply

      Would you recommend this method over a Child’s Theme?
      I have part of a Theme function replaced by some custom code, but included this as part of a Child’s Theme, which also contains some further changes to other .php files.
       
      Would adding all of these changes into 1 new plugin give the same result? (i.e. putting all the changes from the various .php files into 1 plugin file)
       
      Also, will code in a plugin always have precedence (higher priority / loaded last) over code in the original Theme files?

      Jan 1, 2013
      • dhartzler10 Reply

        @Geocaching Studio It’s a step better to put the code in a child theme’s functions.php file, because you won’t have to worry about losing your changes if the main theme is updated. 
         
        But, if you ever change main themes or create a new child theme, then you would have to duplicate your code to the new theme.
         
        And you can bundle all of the extra code into one custom plugin and get the same result as many small different plugins. Official plugins have higher precedence over theme files.

        Jan 2, 2013
    • LehmanCreations Reply

      One thing to note about the MU-Plugins folder is you can not have your plugin inside a sub folder say mu-plugins/myplugin/plugin.php like you can with regular plugins. and there are some things that a MU plugin can not do. i would check out the codex when creating a MU-Plugin

      Jan 8, 2013
      • dhartzler10 Reply

        @LehmanCreations great point Andy! Your plugin must only be one file. @daclements right?

        Jan 10, 2013
        • daclements Reply

          @dhartzler10  @LehmanCreations  @daclements Yes that’s right. There’s some good information about the differences between mu-plugins and regular plugins in the Codex: http://codex.wordpress.org/Must_Use_Plugins

          Jan 11, 2013

Leave a Reply to dhartzler10Cancel reply