Simplifying Theme FunctionalityChip Bennett, WordCamp Kansas City, 02 June 2012                 @chip_bennett
Simplifying Theme FunctionalityAudience:DevelopersNew and Derivative ThemesWhy Simplify?De-crappifying header.phpStreamlin...
Why Simplify?     “Make everything as simple as possible, but not simpler.”                                               ...
Simplifying Theme FunctionalityWhy Simplify?T h e m e M a in t e n a n c e & S u p p o r tS im p lif y in g T h e m e f u ...
Simplifying Theme FunctionalityWhy Simplify?Theme Maintenance & SupportSimplifying Theme functionality will facilitate mai...
Simplifying Theme FunctionalityWhy Simplify?Theme Maintenance & SupportSimplifying Theme functionality will facilitate mai...
De-Crappifying header.php      ...because whats there doesnt really need to be there7                WordCamp Kansas City:...
Simplifying Theme FunctionalityDe-Crappifying header.php<?php wp_title(); ?><title><?php                                  ...
Simplifying Theme FunctionalityDe-Crappifying header.php<?php wp_title(); ?><title><?php                                  ...
Simplifying Theme FunctionalityDe-Crappifying header.php<?php wp_title(); ?>functions.php  f u n c t i o n t h e m e n a m...
Simplifying Theme FunctionalityDe-Crappifying header.phpRSS Feed Links<link rel="alternate" type="application/rss+xml" tit...
Simplifying Theme FunctionalityDe-Crappifying header.phpRSS Feed Linksfunctions.php      function themename_setup_theme() ...
Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet Links<link href="<?php echo bloginfo(templat...
Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet Linksfunctions.php: Scriptsfunction themenam...
Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet LinksProtip: wp_enqueue_scripts() $deps para...
Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet LinksProtip: wp_enqueue_scripts() $deps para...
Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet LinksProtip: wp_enqueue_scripts() $deps para...
Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet Linksfunctions.php: Stylesheetsfunction them...
Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet Linksheader.php      <?php wp_head(); ?> 19 ...
Simplifying Theme FunctionalityDe-Crappifying header.phpIE Conditional Stylesheets      <!--[if lt IE7]>           <link r...
Simplifying Theme FunctionalityDe-Crappifying header.phpIE Conditional StylesheetsEnter the $wp_styles class, and the $wp_...
Simplifying Theme FunctionalityDe-Crappifying header.phpIE Conditional Stylesheetsfunctions.php:function themename_enqueue...
Simplifying Theme FunctionalityDe-Crappifying header.phpIE Conditional Stylesheetsfunctions.php:function themename_enqueue...
Simplifying Theme FunctionalityDe-Crappifying header.phpIE Conditional Stylesheetsheader.php      <?php wp_head(); ?> 24  ...
Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply Script      <?php      if (      comments_open() && ...
Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply Script      <?php      if (      comments_open() && ...
Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply ScriptMeet the comment_form_before action hook 27   ...
Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply ScriptMeet the comment_form_before action hookfuncti...
Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply ScriptMeet the comment_form_before action hookfuncti...
Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply Scriptheader.php      // Silence is goldencomments.p...
Simplifying Theme FunctionalityDe-Crappifying header.php<?php body_class(); ?><?php$bodyclass = ;// Generic semanticclasse...
Simplifying Theme FunctionalityDe-Crappifying header.php<?php body_class(); ?>functions.php      function themename_filter...
Simplifying Theme FunctionalityDe-Crappifying header.php<?php body_class(); ?> header.php      <body <?php body_class(); ?...
Simplifying Theme FunctionalityDe-Crappifying header.php<?php body_class(); ?> header.php      <body <?php body_class(); ?...
Simplifying Theme FunctionalityDe-Crappifying header.phpPlugin Territory SEO Meta Tags      <!-- Meta -->      <meta chars...
Streamlining functions.php        The 10-minute weight-loss plan for your Theme36          WordCamp Kansas City: 02 June 2...
Simplifying Theme FunctionalityStreamlining functions.phpCallback all the things Function calls not explicitly hooked into...
Simplifying Theme FunctionalityStreamlining functions.phpCallback all the things Before   add_theme_support( custom-backgr...
Simplifying Theme FunctionalityStreamlining functions.phpCallback all the things Before   add_theme_support( custom-backgr...
Simplifying Theme FunctionalityStreamlining functions.phpCallback all the things Before   register_sidebar( array(        ...
Simplifying Theme FunctionalityStreamlining functions.phpCallback all the things Before   register_sidebar( array(        ...
Simplifying Theme FunctionalityStreamlining functions.phpPlugin Territory All of these are functional, rather than present...
Simplifying Theme FunctionalityStreamlining functions.phpPlugin Territory All of these are functional, rather than present...
Simplifying Theme FunctionalityStreamlining functions.phpPlugin Territory All of these are functional, rather than present...
Simplifying Theme FunctionalityStreamlining functions.phpPlugin Territory All of these are functional, rather than present...
Reducing Theme Options                                              Less is more.46       WordCamp Kansas City: 02 June 2012
Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than pre...
Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than pre...
Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than pre...
Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than pre...
Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than pre...
Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than pre...
Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than pre...
Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than pre...
General Clean-Up of Theme Files                                  Pruning to stay healthy55        WordCamp Kansas City: 02...
Simplifying Theme FunctionalityGeneral Clean-Up of Theme FilesU n n e e d e d Te m p l a t e F i l e sU n m o d if ie d t ...
Simplifying Theme FunctionalityGeneral Clean-Up of Theme FilesUnneeded Template FilesUnmodified template files (archive.ph...
Simplifying Theme FunctionalityGeneral Clean-Up of Theme FilesUnneeded Template FilesUnmodified template files (archive.ph...
Simplifying Theme FunctionalityGeneral Clean-Up of Theme FilesUnneeded Template FilesUnmodified template files (archive.ph...
Unneeded Callbacks/Functions     Purposeful derivatives of Twenty Ten and Twenty Eleven60                WordCamp Kansas C...
Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsComment List Callbackfunction twentyeleven_comment( $comment, $...
Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsComment List Callbackfunction twentyeleven_comment( $comment, $...
Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsComment List Callbackfunction twentyeleven_comment( $comment, $...
Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsComment List Callbackfunction twentyeleven_comment( $comment, $...
Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsContent FiltersIf you dont need it, just remove it:// C u s t o...
Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsContent FiltersIf you dont need it, just remove it:// Custom ex...
Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsContent FiltersIf you dont need it, just remove it:// Custom ex...
Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsContent FiltersIf you dont need it, just remove it:// Custom ex...
Feedback     You’ve heard from me; now I want to hear from you69           WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality                 Questions? 70                WordCamp Kansas City: 02 June 2012
Upcoming SlideShare
Loading in …5
×

WordCamp KC 2012: Simplifying Theme Functionality

6,195 views

Published on

This session will focus on ways to simplify Theme functionality when forking a Theme or creating a Child Theme. Often, forked Themes and Child Themes needlessly replicate functionality, leave behind unneeded files and resources. Similarly, custom Themes add functionality inefficiently, or implement a glut of Theme options. This session will help developers make their Themes much more easy to maintain, to update, and to support – and maybe even a bit lighter and faster to load. Some topics covered include: reducing unnecessary Theme options, eliminating unneeded callbacks and custom functions, proper filtering of content, and general cleanup of Theme files.

Published in: Technology, Business
1 Comment
4 Likes
Statistics
Notes
  • Great slides! I'm looking forward to watching you session on WordPress.tv.
    Do you consider writing a blog post about these things?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
6,195
On SlideShare
0
From Embeds
0
Number of Embeds
205
Actions
Shares
0
Downloads
34
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

WordCamp KC 2012: Simplifying Theme Functionality

  1. Simplifying Theme FunctionalityChip Bennett, WordCamp Kansas City, 02 June 2012 @chip_bennett
  2. Simplifying Theme FunctionalityAudience:DevelopersNew and Derivative ThemesWhy Simplify?De-crappifying header.phpStreamlining functions.phpReducing Theme OptionsGeneral Clean-Up of Theme FilesUnneeded Functions/Callbacks (Twenty Ten/Twenty Eleven Derivatives) 2 WordCamp Kansas City: 02 June 2012
  3. Why Simplify? “Make everything as simple as possible, but not simpler.” - Albert Einstein3 WordCamp Kansas City: 02 June 2012
  4. Simplifying Theme FunctionalityWhy Simplify?T h e m e M a in t e n a n c e & S u p p o r tS im p lif y in g T h e m e f u n c t io n a lit y w ill 4 WordCamp Kansas City: 02 June 2012
  5. Simplifying Theme FunctionalityWhy Simplify?Theme Maintenance & SupportSimplifying Theme functionality will facilitate maintenance,P l u g i n S u p p o r t /I n t e g r a t i o nS im p lif y in g T h e m e f u n c t io n a lit y w ill 5 WordCamp Kansas City: 02 June 2012
  6. Simplifying Theme FunctionalityWhy Simplify?Theme Maintenance & SupportSimplifying Theme functionality will facilitate maintenance,Plugin Support/IntegrationSimplifying Theme functionality will facilitate out-of-the-boxC h ild T h e m e sS im p lif y in g T h e m e f u n c t io n a lit y w ill 6 WordCamp Kansas City: 02 June 2012
  7. De-Crappifying header.php ...because whats there doesnt really need to be there7 WordCamp Kansas City: 02 June 2012
  8. Simplifying Theme FunctionalityDe-Crappifying header.php<?php wp_title(); ?><title><?php Your SEO Plugin is crying.if (is_home()) { bloginfo(name);} elseif (is_404()) { echo 404 Not Found; echo | ;bloginfo(name);} elseif (is_category()) { echo Category:; wp_title(); echo | ; bloginfo(name);} elseif (is_search()) { echo Search Results; echo | ;bloginfo(name);} elseif ( is_day() || is_month() ||is_year() ) { echo Archives:; wp_title(); echo 8 WordCamp Kansas City: 02 June 2012
  9. Simplifying Theme FunctionalityDe-Crappifying header.php<?php wp_title(); ?><title><?php Your SEO Plugin is crying.if (is_home()) {bloginfo(name);} elseif (is_404()) { The wp_title filter is yourecho 404 Not Found; echo | ;bloginfo(name); friend.} elseif (is_category()) {echo Category:; wp_title(); echo | ;bloginfo(name);} elseif (is_search()) {echo Search Results; echo | ;bloginfo(name);} elseif ( is_day() || is_month() ||is_year() ) {echo Archives:; wp_title(); echo | ; 9 WordCamp Kansas City: 02 June 2012
  10. Simplifying Theme FunctionalityDe-Crappifying header.php<?php wp_title(); ?>functions.php f u n c t i o n t h e m e n a m e _f i l t e r _w p _t i t l e ( $ t i t l e ) { $new_title = ; if (is_home()) { $new_title = esc_attr( get_bloginfo( name ) ); } elseif (is_404()) { $new_title = 404 Not Found . | . esc_attr( get_bloginfo( name ) ); } elseif (is_category()) { // etc...header.php <title><?php wp_title(); ?></title> 10 WordCamp Kansas City: 02 June 2012
  11. Simplifying Theme FunctionalityDe-Crappifying header.phpRSS Feed Links<link rel="alternate" type="application/rss+xml" title="<?php bloginfo(name); ?> RSS 2.0Feed" href="<?php bloginfo(rss2_url); ?>" /><link rel="alternate" type="text/xml" title="<?php bloginfo(name); ?> RSSFeed" href="<?php bloginfo(rss_url); ?>" /><link rel="alternate" type="application/atom+xml" title="<?phpbloginfo(name); ?> Atom 0.3" href="<?php bloginfo(atom_url); ?>" /> Let WordPress do this for you! 11 WordCamp Kansas City: 02 June 2012
  12. Simplifying Theme FunctionalityDe-Crappifying header.phpRSS Feed Linksfunctions.php function themename_setup_theme() { a d d _t h e m e _s u p p o r t ( a u t o m a t i c - f e e d - lin k s ) ; } add_action( wp_title, themename_setup_theme );header.php <?php wp_head(); ?> 12 WordCamp Kansas City: 02 June 2012
  13. Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet Links<link href="<?php echo bloginfo(template_url); ?>/library/js/swfupload/default.css"rel="stylesheet" type="text/css" /><link href="<?php bloginfo(template_directory); ?>/library/css/slimbox.css"rel="stylesheet" type="text/css" /><script src="<?php bloginfo(template_directory); ?>/library/js/jquery-1.3.2.min.js" type="text/javascript"></script><script src="<?php bloginfo(template_directory); ? How many things can you find wrong with this? (If we have time, well come back to this slide later.) 13 WordCamp Kansas City: 02 June 2012
  14. Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet Linksfunctions.php: Scriptsfunction themename_enqueue_scripts() { wp_enqueue_script( jquery ); wp_enqueue_script( nivo, get_template_directory_uri() ./library/js/jquery.nivo.slider.pack.js, array( jquery ) );}add_action( wp_enqueue_scripts, themename_enqueue_scripts );header.php <?php wp_head(); ?> 14 WordCamp Kansas City: 02 June 2012
  15. Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet LinksProtip: wp_enqueue_scripts() $deps parameterfunction themename_enqueue_scripts() { wp_enqueue_script( j q u e r y ); wp_enqueue_script( nivo, get_template_directory_uri() ./library/js/jquery.nivo.slider.pack.js, a r r a y ( j q u e r y ) );}add_action( wp_enqueue_scripts, themename_enqueue_scripts ); 15 WordCamp Kansas City: 02 June 2012
  16. Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet LinksProtip: wp_enqueue_scripts() $deps parameterfunction themename_enqueue_scripts() { wp_enqueue_script( j q u e r y ); wp_enqueue_script( nivo, get_template_directory_uri() ./library/js/jquery.nivo.slider.pack.js, a r r a y ( j q u e r y ) );}add_action( wp_enqueue_scripts, themename_enqueue_scripts );Because jquery is listed as a dependency of nivo, wp_enqueue_script() willenqueue it automatically! No need to call wp_enqueue_script( jquery ): 16 WordCamp Kansas City: 02 June 2012
  17. Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet LinksProtip: wp_enqueue_scripts() $deps parameterfunction themename_enqueue_scripts() { wp_enqueue_script( jquery ); wp_enqueue_script( nivo, get_template_directory_uri() ./library/js/jquery.nivo.slider.pack.js, array( jquery ) );}add_action( wp_enqueue_scripts, themename_enqueue_scripts );Because jquery is listed as a dependency of nivo, wp_enqueue_script() willenqueue it automatically! No need to call wp_enqueue_script( jquery ):f u n c t i o n t h e m e n a m e _e n q u e u e _s c r i p t s ( ) { w p _e n q u e u e _s c r i p t ( n i v o ,g e t _t e m p l a t e _d i r e c t o r y _u r i ( ) . /l i b r a r y /j s /j q u e r y . n i v o . s l i d e r . p a c k . j s , a r r a y ( j q u e r y ) ) ;}a d d _a c t i o n ( w p _e n q u e u e _s c r i p t s , 17 WordCamp Kansas City: 02 June 2012
  18. Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet Linksfunctions.php: Stylesheetsfunction themename_enqueue_styles() { wp_enqueue_style( swfupload-css, get_template_directory_uri() ./library/js/swfupload/default.css ); wp_enqueue_style( slimbox-css, get_template_directory_uri() ./library/css/slimbox.css );}add_action( wp_enqueue_scripts, themename_enqueue_styles ); 18 WordCamp Kansas City: 02 June 2012
  19. Simplifying Theme FunctionalityDe-Crappifying header.phpScript and Stylesheet Linksheader.php <?php wp_head(); ?> 19 WordCamp Kansas City: 02 June 2012
  20. Simplifying Theme FunctionalityDe-Crappifying header.phpIE Conditional Stylesheets <!--[if lt IE7]> <link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri() . /library/css/ie6.css; ?>" /> <![endif]--> <!--[if lt IE8]> <link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri() . /library/css/ie7.css; ?>" /> <![endif]--> <!--[if lte IE9]> But wp_enqueue_style() doesnt have a parameter for IE conditionals... 20 WordCamp Kansas City: 02 June 2012
  21. Simplifying Theme FunctionalityDe-Crappifying header.phpIE Conditional StylesheetsEnter the $wp_styles class, and the $wp_styles->add_data() member function: wp_register_style( $handle, $src ); global $wp_styles; $ w p _s t y l e s - >a d d _d a t a ( $ h a n d l e , c o n d i t i o n a l , $ c o n d it io n ) ; wp_enqueue_style( $handle );Just call $wp_styles->add_data() after the stylesheet is registered, but before it is enqueued. 21 WordCamp Kansas City: 02 June 2012
  22. Simplifying Theme FunctionalityDe-Crappifying header.phpIE Conditional Stylesheetsfunctions.php:function themename_enqueue_styles() { wp_enqueue_style( swfupload-css, get_template_directory_uri() ./library/js/swfupload/default.css ); wp_enqueue_style( slimbox-css, get_template_directory_uri() ./library/css/slimbox.css ); // Conditional stylesheets global $wp_styles; // IE6 wp_register_style( ie6-css, get_template_directory_uri() . /library/css/ie6.css ); $ w p _s t y l e s - >a d d _d a t a ( i e 6 - c s s , c o n d i t i o n a l , lt IE 7 ) ; wp_enqueue_style( ie6-css ); 22 WordCamp Kansas City: 02 June 2012
  23. Simplifying Theme FunctionalityDe-Crappifying header.phpIE Conditional Stylesheetsfunctions.php:function themename_enqueue_styles() { wp_enqueue_style( swfupload-css, get_template_directory_uri() ./library/js/swfupload/default.css ); wp_enqueue_style( slimbox-css, get_template_directory_uri() ./library/css/slimbox.css ); // Conditional stylesheets global $wp_styles; // IE6 wp_register_style( ie6-css, get_template_directory_uri() . /library/css/ie6.css ); $wp_styles->add_data( ie6-css, conditional, lt IE7 ); wp_enqueue_style( ie6-css ); // IE7PROTIP: Possibly coming soon to a wp_enqueue_script() near you. See Tracticket #16024 23 WordCamp Kansas City: 02 June 2012
  24. Simplifying Theme FunctionalityDe-Crappifying header.phpIE Conditional Stylesheetsheader.php <?php wp_head(); ?> 24 WordCamp Kansas City: 02 June 2012
  25. Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply Script <?php if ( comments_open() && is_singular() && get_option( thread_comments ) ) { wp_enqueue_script( comment-reply ); } ?>Okay, this ones not bad. But it calls wp_enqueue_script(), so we shouldput it in our script-enqueueing callback in functions.php, right? 25 WordCamp Kansas City: 02 June 2012
  26. Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply Script <?php if ( comments_open() && is_singular() && get_option( thread_comments ) ) { wp_enqueue_script( comment-reply ); } ?>Okay, this ones not bad. But it calls wp_enqueue_script(), so we shouldput it in our script-enqueueing callback in functions.php, right?How about an even better shortcut...? 26 WordCamp Kansas City: 02 June 2012
  27. Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply ScriptMeet the comment_form_before action hook 27 WordCamp Kansas City: 02 June 2012
  28. Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply ScriptMeet the comment_form_before action hookfunctions.php: function themename_enqueue_comment_reply_script() { if ( get_option( thread_comments ) ) { wp_enqueue_script( comment-reply ); } } add_action( c o m m e n t _f o r m _b e f o r e , themename_enqueue_comment_reply_script ); 28 WordCamp Kansas City: 02 June 2012
  29. Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply ScriptMeet the comment_form_before action hookfunctions.php: function themename_enqueue_comment_reply_script() { if ( get_option( thread_comments ) ) { wp_enqueue_script( comment-reply ); } } add_action( c o m m e n t _f o r m _b e f o r e , themename_enqueue_comment_reply_script ); Thanks to changes in WordPress 3.3, we can now call wp_enqueue_script() inline, rather than only in the header or footer. By using the comment_form_before action hook, we can skip the conditional checks for comments_open() and is_singular(). 29 WordCamp Kansas City: 02 June 2012
  30. Simplifying Theme FunctionalityDe-Crappifying header.phpComment-Reply Scriptheader.php // Silence is goldencomments.php <?php comment_form(); ?> 30 WordCamp Kansas City: 02 June 2012
  31. Simplifying Theme FunctionalityDe-Crappifying header.php<?php body_class(); ?><?php$bodyclass = ;// Generic semanticclassesif ( is_front_page() ) { $bodyclass = O <body <?php themename_custom_body_class(); ?>>home;} else if { is_home() ) { R $bodyclass = blog;} else if { is_archive() ) { $bodyclass =archive;} else if { is_date() ) { $bodyclass = date;} else if { is_search() ) { 31 WordCamp Kansas City: 02 June 2012
  32. Simplifying Theme FunctionalityDe-Crappifying header.php<?php body_class(); ?>functions.php function themename_filter_body_class( $ c l a s s e s ) { $bodyclass = false; if ( is_front_page() ) { $bodyclass = home; } else if { is_home() ) { $bodyclass = blog; } else if { is_archive() ) { $bodyclass = archive; } else if { is_date() ) { // etc... } 32 if ( $bodyclassWordCamp Kansas City: 02 June 2012 ){
  33. Simplifying Theme FunctionalityDe-Crappifying header.php<?php body_class(); ?> header.php <body <?php body_class(); ?> 33 WordCamp Kansas City: 02 June 2012
  34. Simplifying Theme FunctionalityDe-Crappifying header.php<?php body_class(); ?> header.php <body <?php body_class(); ?> PROTIP: you can do the same thing for post_class(), via the post_class filter. 34 WordCamp Kansas City: 02 June 2012
  35. Simplifying Theme FunctionalityDe-Crappifying header.phpPlugin Territory SEO Meta Tags <!-- Meta --> <meta charset="<?php bloginfo(charset); ?>" /> <meta name="Generator" content="WordPress" /> <meta name="Description" content="<?php bloginfo(description); ?>" /> <meta name="Keywords" content="<?php bloginfo(description); ?> , bunch, of, keywords, stuffed, in, here" /> header.php // silence is golden // just let Plugins handle these 35 WordCamp Kansas City: 02 June 2012
  36. Streamlining functions.php The 10-minute weight-loss plan for your Theme36 WordCamp Kansas City: 02 June 2012
  37. Simplifying Theme FunctionalityStreamlining functions.phpCallback all the things Function calls not explicitly hooked into an action hook via callback will fire at after_setup_theme, which may not be the appropriate action hook for the function being called. Also, function calls not explicitly hooked into an action hook via callback cannot be overridden via remove_action(). 37 WordCamp Kansas City: 02 June 2012
  38. Simplifying Theme FunctionalityStreamlining functions.phpCallback all the things Before add_theme_support( custom-background ); add_theme_support( custom-header ); add_theme_support( automatic-feed-links ); add_theme_support( post-thumbnails ); register_nav_menus( array( 38 WordCamp Kansas City: 02 June 2012
  39. Simplifying Theme FunctionalityStreamlining functions.phpCallback all the things Before add_theme_support( custom-background ); add_theme_support( custom-header ); add_theme_support( automatic-feed-links ); add_theme_support( post-thumbnails ); register_nav_menus( array( After function themename_setup_theme() { add_theme_support( custom-background ); add_theme_support( custom-header ); add_theme_support( automatic-feed-links ); add_theme_support( post-thumbnails ); register_nav_menus( array( header => Header Menu ) ); 39 WordCamp Kansas City: 02 June 2012
  40. Simplifying Theme FunctionalityStreamlining functions.phpCallback all the things Before register_sidebar( array( // Args array ) ); 40 WordCamp Kansas City: 02 June 2012
  41. Simplifying Theme FunctionalityStreamlining functions.phpCallback all the things Before register_sidebar( array( // Args array ) ); After function themename_widgets_init() { register_sidebar( array( // Args array ) ); } add_action( widgets_init, themename_widgets_init ); 41 WordCamp Kansas City: 02 June 2012
  42. Simplifying Theme FunctionalityStreamlining functions.phpPlugin Territory All of these are functional, rather than presentational, and therefore should be handled by Plugins rather than by the Theme: // Clean up the <head> function removeHeadLinks() { remove_action(wp_head, rsd_link); remove_action(wp_head, wlwmanifest_link); } add_action(init, removeHeadLinks); remove_action(wp_head, wp_generator); // Disable admin bar function themename_disable_admin_bar() { add_filter( show_admin_bar, __return_false ); 42 WordCamp Kansas City: 02 June 2012
  43. Simplifying Theme FunctionalityStreamlining functions.phpPlugin Territory All of these are functional, rather than presentational, and therefore should be handled by Plugins rather than by the Theme: // C l e a n u p t h e <h e a d > f u n c t io n r e m o v e H e a d L in k s ( ) { r e m o v e _a c t i o n ( w p _h e a d , r s d _l i n k ) ; r e m o v e _a c t i o n ( w p _h e a d , w l w m a n i f e s t _l i n k ) ; } a d d _a c t i o n ( i n i t , r e m o v e H e a d L i n k s ) ; r e m o v e _a c t i o n ( w p _h e a d , w p _g e n e r a t o r ) ; // Disable admin bar 43 function themename_disable_admin_bar() { WordCamp Kansas City: 02 June 2012
  44. Simplifying Theme FunctionalityStreamlining functions.phpPlugin Territory All of these are functional, rather than presentational, and therefore should be handled by Plugins rather than by the Theme: // Clean up the <head> function removeHeadLinks() { remove_action(wp_head, rsd_link); remove_action(wp_head, wlwmanifest_link); } add_action(init, removeHeadLinks); remove_action(wp_head, wp_generator); // D i s a b l e a d m i n b a r f u n c t io n t h e m e n a m e _d i s a b l e _a d m i n _b a r ( ) { 44 WordCamp Kansas City: 02 June 2012
  45. Simplifying Theme FunctionalityStreamlining functions.phpPlugin Territory All of these are functional, rather than presentational, and therefore should be handled by Plugins rather than by the Theme: // Clean up the <head> function removeHeadLinks() { remove_action(wp_head, rsd_link); remove_action(wp_head, wlwmanifest_link); } add_action(init, removeHeadLinks); remove_action(wp_head, wp_generator); // Disable admin bar function themename_disable_admin_bar() { add_filter( show_admin_bar, __return_false ); 45 WordCamp Kansas City: 02 June 2012
  46. Reducing Theme Options Less is more.46 WordCamp Kansas City: 02 June 2012
  47. Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than presentational, and thereforeshould be left to Plugins:F a v ic o n 47 WordCamp Kansas City: 02 June 2012
  48. Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than presentational, and thereforeshould be left to Plugins:FaviconG o o g le A n a ly t ic s 48 WordCamp Kansas City: 02 June 2012
  49. Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than presentational, and thereforeshould be left to Plugins:FaviconGoogle AnalyticsS E O M e t a Ta g s 49 WordCamp Kansas City: 02 June 2012
  50. Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than presentational, and thereforeshould be left to Plugins:FaviconGoogle AnalyticsSEO Meta TagsR o b o ts .tx t 50 WordCamp Kansas City: 02 June 2012
  51. Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than presentational, and thereforeshould be left to Plugins:FaviconGoogle AnalyticsSEO Meta TagsRobots.txtD i s a b l i n g t h e A d m i n To o l b a r 51 WordCamp Kansas City: 02 June 2012
  52. Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than presentational, and thereforeshould be left to Plugins:FaviconGoogle AnalyticsSEO Meta TagsRobots.txtDisabling the Admin ToolbarG Z i p p i n g /c o m p r e s s i n g /m i n i m i z i n gr e s o u r c e s /c o n t e n t 52 WordCamp Kansas City: 02 June 2012
  53. Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than presentational, and thereforeshould be left to Plugins:FaviconGoogle AnalyticsSEO Meta TagsRobots.txtDisabling the Admin ToolbarGZipping/compressing/minimizing resources/contentR e p la c in g c o r e -b u n d le d s c r ip t s w it h C D N -h o s t e d 53 WordCamp Kansas City: 02 June 2012
  54. Simplifying Theme FunctionalityReducing Theme OptionsPlugin TerritoryThe following options are functional, rather than presentational, and thereforeshould be left to Plugins:FaviconGoogle AnalyticsSEO Meta TagsRobots.txtDisabling the Admin ToolbarGZipping/compressing/minimizing resources/contentReplacing core-bundled scripts with CDN-hosted versionsChild Theme TerritoryThe following options are ideal candidates for customization via Child Themerather than via Theme options:C us to m C S S 54 WordCamp Kansas City: 02 June 2012
  55. General Clean-Up of Theme Files Pruning to stay healthy55 WordCamp Kansas City: 02 June 2012
  56. Simplifying Theme FunctionalityGeneral Clean-Up of Theme FilesU n n e e d e d Te m p l a t e F i l e sU n m o d if ie d t e m p la t e f ile s ( a r c h iv e . p h p ,a u t h o r . p h p , c a t e g o r y. p h p , d a t e . p h p , t a g . p h p , e t c . ) .DRY 56 WordCamp Kansas City: 02 June 2012
  57. Simplifying Theme FunctionalityGeneral Clean-Up of Theme FilesUnneeded Template FilesUnmodified template files (archive.php, author.php, category.php, date.php,tag.php, etc.). DRYU n n e e d e d Te m p l a t e - P a r t F i l e sM in im a lly m o d if ie d t e m p la t e -p a r t f ile s( s e a r c h fo r m .p h p ) 57 WordCamp Kansas City: 02 June 2012
  58. Simplifying Theme FunctionalityGeneral Clean-Up of Theme FilesUnneeded Template FilesUnmodified template files (archive.php, author.php, category.php, date.php,tag.php, etc.). DRYUnneeded Template-Part FilesMinimally modified template-part files (searchform.php)U n n e e d e d D e v e lo p m e n t F ile s__M A C O S X 58 WordCamp Kansas City: 02 June 2012
  59. Simplifying Theme FunctionalityGeneral Clean-Up of Theme FilesUnneeded Template FilesUnmodified template files (archive.php, author.php, category.php, date.php,tag.php, etc.). DRYUnneeded Template-Part FilesMinimally modified template-part files (searchform.php)Unneeded Development Files__MACOSXU n n e e d e d V C S F ile s. g it , . s v n , e t c . 59 WordCamp Kansas City: 02 June 2012
  60. Unneeded Callbacks/Functions Purposeful derivatives of Twenty Ten and Twenty Eleven60 WordCamp Kansas City: 02 June 2012
  61. Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsComment List Callbackfunction twentyeleven_comment( $comment, $args, $depth ) {} 61 WordCamp Kansas City: 02 June 2012
  62. Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsComment List Callbackfunction twentyeleven_comment( $comment, $args, $depth ) {}Consider using the default comment-list walker:// D e f a u l t o u t p u tw p _l i s t _c o m m e n t s ( ) ; 62 WordCamp Kansas City: 02 June 2012
  63. Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsComment List Callbackfunction twentyeleven_comment( $comment, $args, $depth ) {}Consider using the default comment-list walker:// Default outputwp_list_comments();// S p l i t C o m m e n t s a n d P i n g sw p _l i s t _c o m m e n t s ( a r r a y ( t y p e => c o m m e n t ) ;w p _l i s t _c o m m e n t s ( a r r a y ( t y p e => p i n g s ) ; 63 WordCamp Kansas City: 02 June 2012
  64. Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsComment List Callbackfunction twentyeleven_comment( $comment, $args, $depth ) {}Consider using the default comment-list walker:// Default outputwp_list_comments();// Split Comments and Pingswp_list_comments( array( type => comment );wp_list_comments( array( type => pings );// M o d i f y a v a t a r s i z e :w p _l i s t _c o m m e n t s ( a r r a y ( a v a t a r _s i z e => 4 0 ) ; 64 WordCamp Kansas City: 02 June 2012
  65. Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsContent FiltersIf you dont need it, just remove it:// C u s t o m e x c e r p t l e n g t h . D e f a u l t v a l u e i s 5 5 ; F i l t e rv a lu e is 4 0f u n c t i o n t w e n t y t e n _e x c e r p t _l e n g t h ( $ l e n g t h ) { re turn 4 0 ; 65 WordCamp Kansas City: 02 June 2012
  66. Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsContent FiltersIf you dont need it, just remove it:// Custom excerpt length. Default value is 55; Filter value is 40function twentyten_excerpt_length( $length ) { return 40;}// C u s t o m e x c e r p t " m o r e " t e x t ( a u t o - g e n e r a t e d ) .D e f a u l t v a l u e i s [ …] f u n c t i o n t w e n t y t e n _a u t o _e x c e r p t _m o r e ( $ m o r e ) { r e t u r n & h e llip ; . 66 WordCamp Kansas City: 02 June 2012
  67. Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsContent FiltersIf you dont need it, just remove it:// Custom excerpt length. Default value is 55; Filter value is 40function twentyten_excerpt_length( $length ) { return 40;}// Custom excerpt "more" text (auto-generated). Default value is […]function twentyten_auto_excerpt_more( $more ) { return &hellip; . twentyten_continue_reading_link();}// C u s t o m e x c e r p t " m o r e " t e x t ( m a n u a l ) . D e f a u l tv a lu e is [ . . . ] ;f u n c t i o n t w e n t y t e n _c u s t o m _e x c e r p t _m o r e ( $ o u t p u t ) { i f ( h a s _e x c e r p t ( ) & & ! i s _a t t a c h m e n t ( ) ) { $ o u t p u t . = t w e n t y t e n _c o n t i n u e _r e a d i n g _l i n k ( ) ; } 67 WordCamp Kansas City: 02 June 2012
  68. Simplifying Theme FunctionalityUnneeded Callbacks/FunctionsContent FiltersIf you dont need it, just remove it:// Custom excerpt length. Default value is 55; Filter value is 40function twentyten_excerpt_length( $length ) { return 40;}// Custom excerpt "more" text (auto-generated). Default value is […]function twentyten_auto_excerpt_more( $more ) { return &hellip; . twentyten_continue_reading_link();}// Custom excerpt "more" text (manual). Default value is [...];function twentyten_custom_excerpt_more( $output ) { if ( has_excerpt() && ! is_attachment() ) { $output .= twentyten_continue_reading_link(); }// G a l l e r y s t y l e . O n l y u s e t h i s i f y o u i n t e n d t o d e f i n ey o u r o w n G a lle r y C S Sa 68 d _f i l t e r ( u s e _d e f a u l t _g a l l e r y _s t y l e , d WordCamp Kansas City: 02 June 2012
  69. Feedback You’ve heard from me; now I want to hear from you69 WordCamp Kansas City: 02 June 2012
  70. Simplifying Theme Functionality Questions? 70 WordCamp Kansas City: 02 June 2012

×