Free Webinar

Replay Now Available!
How to Build a WordPress Plugin
Watch Today!

Webinar Replays

Miss the live version?
Watch the Video Replay Now!
View Today!

Hi! I'm Dustin

My Goal is to Inspire You to
Do Amazing Things with WordPress
Learn More about Me
108 – The Dangers of the functions.php File
 
Play
Announcements

– WordPress Webinar on Custom Post Types on January 4th at 10am EST (http://yourwebsiteengineer.com/webinar)

Advanced WordPress Developers Course
– Last week in January
– Take your developer skills to a whole new level
– Sign up below to be notified

Become an insider and get exclusive deals + free eBook!



No Spam. Not Ever. We Hate it Too!

Weekly Newsletters
– Premium Content will begin in January! Join the mailing list to find out more!

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

– Sign up for webinar at http://yourwebsiteengineer.com/webinar

Published on: 26 Dec | Podcast | 10 responses| Tags: ,

Subscribe and Never Miss an Episode

               
9 comments
LehmanCreations
LehmanCreations

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

Geocaching Studio
Geocaching Studio

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?

forresttanaka
forresttanaka

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.

dhartzler10
dhartzler10 moderator

 @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.

dhartzler10
dhartzler10 moderator

 @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.

daclements
daclements

@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 :)

forresttanaka
forresttanaka

 @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!