Your SlideShare is downloading. ×
“Just paste this code in your                           functions.php”Rick Radko                        WordCamp Torontor3...
SlidesSlides will be posted:   http://www.slideshare.net/r3df© 2011 Rick Radko, r3df.com          1
Who am I?I’m   Rick Radko   Developer, coder and web designer   WordPress enthusiast© 2011 Rick Radko, r3df.com        ...
Who are you?© 2011 Rick Radko, r3df.com   3
“Just paste this code in your functions.php”© 2011 Rick Radko, r3df.com                    4
Automatic theme updates© 2011 Rick Radko, r3df.com   5
Oh-oh!© 2011 Rick Radko, r3df.com   6
Does it change your theme?Non-Theme related changes   Like buttons, thickbox effects, fancy jQuery effects    and addons ...
Don’t do it!                              “Just paste this code in your                                            functio...
Then where?Child theme   All theme related changes.   Changes that should go away if theme changes.Personal “Site” plugi...
Child themesHow do they work?   Child themes inherit all the features of their parent    theme.   Child themes override ...
Minimal child themeWhat do you need for a minimal child theme?   A theme folder.   A file called style.css, with a speci...
Creating a child themeLots of ways to create the theme content, here area few:   Text editor and ftp the files into place...
cPanel© 2011 Rick Radko, r3df.com   13
File manager© 2011 Rick Radko, r3df.com   14
Create the child theme folderCreate a new folder in /wp-content/themes.© 2011 Rick Radko, r3df.com                  15
New child-theme folder© 2011 Rick Radko, r3df.com   16
Creating a style.cssCreate style.css in the theme folder.© 2011 Rick Radko, r3df.com             17
The style.css file© 2011 Rick Radko, r3df.com   18
Absolute minimum style.css© 2011 Rick Radko, r3df.com   19
The new child themeNow you have a new theme!© 2011 Rick Radko, r3df.com   20
The new theme, not quite rightChild Theme                                 Twenty Eleven© 2011 Rick Radko, r3df.com        ...
Practical style.cssA style.css that will work a little better:© 2011 Rick Radko, r3df.com                   22
Child theme activated© 2011 Rick Radko, r3df.com   23
Now, it’s the same as the parent© 2011 Rick Radko, r3df.com        24
Creating a functions.phpCreate functions.php in the theme folder.© 2011 Rick Radko, r3df.com                 25
Edit the functions.php© 2011 Rick Radko, r3df.com   26
Minimum functions.php© 2011 Rick Radko, r3df.com   27
It’s done!We now have a child theme that:   Looks exactly the same as it’s parent.   Will maintain updates/changes to it...
“Grandchild” issuesYou cannot make a child theme of a child theme!   Use a site plugin.© 2011 Rick Radko, r3df.com       ...
Site pluginsWhat do you need for a minimal plugin?   Only a single php file, of any name.   Plugin defining header in th...
Creating a site pluginGo to file manager again© 2011 Rick Radko, r3df.com   31
Creating the plugin folder© 2011 Rick Radko, r3df.com   32
The new site-plugin folder© 2011 Rick Radko, r3df.com   33
Create a site-plugin.php file© 2011 Rick Radko, r3df.com     34
The site-plugin.php file© 2011 Rick Radko, r3df.com   35
Minimum plugin file© 2011 Rick Radko, r3df.com   36
The new plugin© 2011 Rick Radko, r3df.com   37
Practical plugin file© 2011 Rick Radko, r3df.com   38
Activated final pluginactivate© 2011 Rick Radko, r3df.com   39
It’s done!We now have a complete plugin that:   Stores code without direct impact from updates.   Can be extended       ...
Timing issues   Plugins load before themes.   For most snippets that are hooked to an action    this is not an issue, as...
Extras – Theme thumbnailImage for theme thumbnail:   Create an image in png format.   About 300x225px.   Save as “scree...
Extras – Split loadingSplit loading   admin/front/both         is_admin()    /* Code needed by both admin and front here...
Extras – Loading css and javascript  Loading css and scripts  Use actions   wp_print_styles for css   wp_enqueue_scripts...
Key PointsMain theme functions.php is:   Not the best place to put code snippets.   Overwritten by automatic updates.  ...
Key Points: Child ThemesChild themes for theme related changes   They are easy to create:         Can be really simple, ...
Key Points: Personal PluginsPersonal plugin for all other additions/changes:   Also easy to create:         Can be reall...
ContactRick Radko   email: wpinfo@r3df.com   twitter: @r3designforgeSlides at:   www.slideshare.net/r3dfCode at:   r3d...
Upcoming SlideShare
Loading in...5
×

Don't "Just paste this code in your functions.php"

4,709

Published on

Presentation slides from WordCamp Toronto 2011 talk.

Many snippets of code are available on the web to add functionality to your WordPress site. “Just paste this code in your functions.php”, used to be the refrain for adding those functions to your site. Now many themes are using the update system, which will overwrite the functions.php when updating and you will lose your changes!

A lot of functions that are key to your site operation, but not related to the theme, are also now being added to the functions.php. These functions should really be saved somewhere else, so your site won’t break when you change or update themes.

This talk will show anyone who uses WordPress how to easily create a very simple child theme, and a very simple personal plugin for saving theme changes and code snippets. It’s really very easy!

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,709
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Don't "Just paste this code in your functions.php""

  1. 1. “Just paste this code in your functions.php”Rick Radko WordCamp Torontor3df.com November 5th, 2011
  2. 2. SlidesSlides will be posted:  http://www.slideshare.net/r3df© 2011 Rick Radko, r3df.com 1
  3. 3. Who am I?I’m  Rick Radko  Developer, coder and web designer  WordPress enthusiast© 2011 Rick Radko, r3df.com 2
  4. 4. Who are you?© 2011 Rick Radko, r3df.com 3
  5. 5. “Just paste this code in your functions.php”© 2011 Rick Radko, r3df.com 4
  6. 6. Automatic theme updates© 2011 Rick Radko, r3df.com 5
  7. 7. Oh-oh!© 2011 Rick Radko, r3df.com 6
  8. 8. Does it change your theme?Non-Theme related changes  Like buttons, thickbox effects, fancy jQuery effects and addons  Custom taxonomies, custom post types, at least partially.  These changes should be theme independent.  Changes get lost in functions.php theme items.© 2011 Rick Radko, r3df.com 7
  9. 9. Don’t do it! “Just paste this code in your functions.php”© 2011 Rick Radko, r3df.com 8
  10. 10. Then where?Child theme  All theme related changes.  Changes that should go away if theme changes.Personal “Site” plugin  All other additions/changes.  Changes that should stay even if theme changes.*“Site” from Otto: http://ottopress.com/2011/creating-a-site-specific-snippets-plugin© 2011 Rick Radko, r3df.com 9
  11. 11. Child themesHow do they work?  Child themes inherit all the features of their parent theme.  Child themes override their parent theme by providing alternate code/files.  If it’s not present in child, WordPress looks in the parent theme.© 2011 Rick Radko, r3df.com 10
  12. 12. Minimal child themeWhat do you need for a minimal child theme?  A theme folder.  A file called style.css, with a specific header, and usually one line of code.  Not required for a child theme, but a functions.php will be needed to add php snippets.© 2011 Rick Radko, r3df.com 11
  13. 13. Creating a child themeLots of ways to create the theme content, here area few:  Text editor and ftp the files into place  Local development environment and ftp  Tomorrow’s workshops  Site hosting’s filemanager and editor  Common and simple© 2011 Rick Radko, r3df.com 12
  14. 14. cPanel© 2011 Rick Radko, r3df.com 13
  15. 15. File manager© 2011 Rick Radko, r3df.com 14
  16. 16. Create the child theme folderCreate a new folder in /wp-content/themes.© 2011 Rick Radko, r3df.com 15
  17. 17. New child-theme folder© 2011 Rick Radko, r3df.com 16
  18. 18. Creating a style.cssCreate style.css in the theme folder.© 2011 Rick Radko, r3df.com 17
  19. 19. The style.css file© 2011 Rick Radko, r3df.com 18
  20. 20. Absolute minimum style.css© 2011 Rick Radko, r3df.com 19
  21. 21. The new child themeNow you have a new theme!© 2011 Rick Radko, r3df.com 20
  22. 22. The new theme, not quite rightChild Theme Twenty Eleven© 2011 Rick Radko, r3df.com 21
  23. 23. Practical style.cssA style.css that will work a little better:© 2011 Rick Radko, r3df.com 22
  24. 24. Child theme activated© 2011 Rick Radko, r3df.com 23
  25. 25. Now, it’s the same as the parent© 2011 Rick Radko, r3df.com 24
  26. 26. Creating a functions.phpCreate functions.php in the theme folder.© 2011 Rick Radko, r3df.com 25
  27. 27. Edit the functions.php© 2011 Rick Radko, r3df.com 26
  28. 28. Minimum functions.php© 2011 Rick Radko, r3df.com 27
  29. 29. It’s done!We now have a child theme that:  Looks exactly the same as it’s parent.  Will maintain updates/changes to it’s:  style.css  functions.php  any other theme file that you want to add without fear of having them overwritten!© 2011 Rick Radko, r3df.com 28
  30. 30. “Grandchild” issuesYou cannot make a child theme of a child theme!  Use a site plugin.© 2011 Rick Radko, r3df.com 29
  31. 31. Site pluginsWhat do you need for a minimal plugin?  Only a single php file, of any name.  Plugin defining header in the file.  Not required for a plugin, but a folder keeps things neater, especially if you want to include css and js files.© 2011 Rick Radko, r3df.com 30
  32. 32. Creating a site pluginGo to file manager again© 2011 Rick Radko, r3df.com 31
  33. 33. Creating the plugin folder© 2011 Rick Radko, r3df.com 32
  34. 34. The new site-plugin folder© 2011 Rick Radko, r3df.com 33
  35. 35. Create a site-plugin.php file© 2011 Rick Radko, r3df.com 34
  36. 36. The site-plugin.php file© 2011 Rick Radko, r3df.com 35
  37. 37. Minimum plugin file© 2011 Rick Radko, r3df.com 36
  38. 38. The new plugin© 2011 Rick Radko, r3df.com 37
  39. 39. Practical plugin file© 2011 Rick Radko, r3df.com 38
  40. 40. Activated final pluginactivate© 2011 Rick Radko, r3df.com 39
  41. 41. It’s done!We now have a complete plugin that:  Stores code without direct impact from updates.  Can be extended  Inject css and javascript files  Add options pages in admin  Is portable  Easily move from one site to another carrying all your favorite changes.© 2011 Rick Radko, r3df.com 40
  42. 42. Timing issues  Plugins load before themes.  For most snippets that are hooked to an action this is not an issue, as the action dictates when the code runs.  Occasionally there are issues with code that is not hooked to an action, so the code snippet in the plugin may run too early and not work.  Hook the code to an appropriate action with add_action(). codex.wordpress.org/Plugin_API/Action_Reference© 2011 Rick Radko, r3df.com 41
  43. 43. Extras – Theme thumbnailImage for theme thumbnail:  Create an image in png format.  About 300x225px.  Save as “screenshot.png” in the theme folder.  Will be loaded automatically.© 2011 Rick Radko, r3df.com 42
  44. 44. Extras – Split loadingSplit loading  admin/front/both  is_admin() /* Code needed by both admin and front here*/ if ( is_admin() ) { /* code for admin only here*/ } else { /* code for front only here*/ }© 2011 Rick Radko, r3df.com 43
  45. 45. Extras – Loading css and javascript Loading css and scripts Use actions  wp_print_styles for css  wp_enqueue_scripts for scripts See the codex for more detail© 2011 Rick Radko, r3df.com 44
  46. 46. Key PointsMain theme functions.php is:  Not the best place to put code snippets.  Overwritten by automatic updates.  Not used if theme changes.Some snippets are not theme related.  Should have a place that is theme independent to store them.© 2011 Rick Radko, r3df.com 45
  47. 47. Key Points: Child ThemesChild themes for theme related changes  They are easy to create:  Can be really simple, only what you need.  Minimum is a folder and style.css.  Probably will need a functions.php.  Create once per theme.  Once it’s set-up, just paste in your snippets.© 2011 Rick Radko, r3df.com 46
  48. 48. Key Points: Personal PluginsPersonal plugin for all other additions/changes:  Also easy to create:  Can be really simple or quite complex  Minimum is a plugin php file  Folder helps keep things organized  Set-up once per site  copy across sites!  Once it’s set-up, just paste in your snippets.© 2011 Rick Radko, r3df.com 47
  49. 49. ContactRick Radko  email: wpinfo@r3df.com  twitter: @r3designforgeSlides at:  www.slideshare.net/r3dfCode at:  r3df.com/downloads© 2011 Rick Radko, r3df.com 48

×