SlideShare ist ein Scribd-Unternehmen logo
1 von 70
Simplifying Theme Functionality


Chip Bennett, WordCamp Kansas City, 02 June 2012
                 @chip_bennett
Simplifying Theme Functionality
Audience:
Developers
New and Derivative Themes

Why Simplify?

De-crappifying header.php

Streamlining functions.php

Reducing Theme Options

General Clean-Up of Theme Files

Unneeded Functions/Callbacks (Twenty Ten/Twenty Eleven Derivatives)


 2                       WordCamp Kansas City: 02 June 2012
Why Simplify?

     “Make everything as simple as possible, but not simpler.”
                                                        - Albert Einstein




3                  WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Why Simplify?


T h e m e M a in t e n a n c e & S u p p o r t
S 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
Simplifying Theme Functionality
Why Simplify?


Theme Maintenance & Support
Simplifying 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 n
S 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
Simplifying Theme Functionality
Why Simplify?


Theme Maintenance & Support
Simplifying Theme functionality will facilitate maintenance,



Plugin Support/Integration
Simplifying Theme functionality will facilitate out-of-the-box



C h ild T h e m e s
S 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
De-Crappifying header.php

      ...because what's there doesn't really need to be there




7                WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-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
Simplifying Theme Functionality
De-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 your
echo '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
Simplifying Theme Functionality
De-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
Simplifying Theme Functionality
De-Crappifying header.php

RSS Feed Links
<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS 2.0
Feed" href="<?php bloginfo('rss2_url'); ?>" />
<link rel="alternate" type="text/xml" title="<?php bloginfo('name'); ?> RSS
Feed" href="<?php bloginfo('rss_url'); ?>" />
<link rel="alternate" type="application/atom+xml" title="<?php
bloginfo('name'); ?> Atom 0.3" href="<?php bloginfo('atom_url'); ?>" />


   Let WordPress do this for you!




 11                           WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

RSS Feed Links

functions.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
Simplifying Theme Functionality
De-Crappifying header.php

Script 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, we'll come back to this slide later.)




 13                           WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

Script and Stylesheet Links

functions.php: Scripts
function 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
Simplifying Theme Functionality
De-Crappifying header.php

Script and Stylesheet Links
Protip: wp_enqueue_scripts() $deps parameter
function 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
Simplifying Theme Functionality
De-Crappifying header.php

Script and Stylesheet Links
Protip: wp_enqueue_scripts() $deps parameter
function 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() will
enqueue it automatically! No need to call wp_enqueue_script( 'jquery' ):




 16                             WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

Script and Stylesheet Links
Protip: wp_enqueue_scripts() $deps parameter
function 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() will
enqueue 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
Simplifying Theme Functionality
De-Crappifying header.php

Script and Stylesheet Links

functions.php: Stylesheets
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' );
}
add_action( 'wp_enqueue_scripts', 'themename_enqueue_styles' );




 18                           WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

Script and Stylesheet Links



header.php
      <?php wp_head(); ?>




 19                         WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

IE 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() doesn't have a parameter for IE
    conditionals...

 20                         WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

IE Conditional Stylesheets

Enter 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
Simplifying Theme Functionality
De-Crappifying header.php

IE Conditional Stylesheets
functions.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
Simplifying Theme Functionality
De-Crappifying header.php

IE Conditional Stylesheets
functions.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' );
      // IE7
PROTIP: Possibly coming soon to a wp_enqueue_script() near you. See Trac
ticket #16024

 23                             WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

IE Conditional Stylesheets



header.php
      <?php wp_head(); ?>




 24                         WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

Comment-Reply Script
      <?php
      if (
      comments_open() &&
      is_singular() &&
      get_option( 'thread_comments' ) ) {
           wp_enqueue_script( 'comment-reply' );
      }
      ?>
Okay, this one's not bad. But it calls wp_enqueue_script(), so we should
put it in our script-enqueueing callback in functions.php, right?




 25                        WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

Comment-Reply Script
      <?php
      if (
      comments_open() &&
      is_singular() &&
      get_option( 'thread_comments' ) ) {
           wp_enqueue_script( 'comment-reply' );
      }
      ?>
Okay, this one's not bad. But it calls wp_enqueue_script(), so we should
put it in our script-enqueueing callback in functions.php, right?


How about an even better shortcut...?


 26                        WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

Comment-Reply Script
Meet the 'comment_form_before' action hook




 27                     WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

Comment-Reply Script
Meet the 'comment_form_before' action hook

functions.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
Simplifying Theme Functionality
De-Crappifying header.php

Comment-Reply Script
Meet the 'comment_form_before' action hook

functions.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
Simplifying Theme Functionality
De-Crappifying header.php

Comment-Reply Script

header.php
      // Silence is golden



comments.php
      <?php comment_form(); ?>




 30                          WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-Crappifying header.php

<?php body_class(); ?>
<?php
$bodyclass = '';
// Generic semantic
classes
if ( 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
Simplifying Theme Functionality
De-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
                           ){
Simplifying Theme Functionality
De-Crappifying header.php

<?php body_class(); ?>



 header.php
      <body <?php body_class(); ?>




 33                         WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
De-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
Simplifying Theme Functionality
De-Crappifying header.php

Plugin 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
Streamlining functions.php

        The 10-minute weight-loss plan for your Theme




36          WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Streamlining functions.php

Callback 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
Simplifying Theme Functionality
Streamlining functions.php

Callback 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
Simplifying Theme Functionality
Streamlining functions.php

Callback 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
Simplifying Theme Functionality
Streamlining functions.php

Callback all the things
 Before
   register_sidebar( array(
        // Args array
   ) );




 40                      WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Streamlining functions.php

Callback 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
Simplifying Theme Functionality
Streamlining functions.php

Plugin 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
Simplifying Theme Functionality
Streamlining functions.php

Plugin 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
Simplifying Theme Functionality
Streamlining functions.php

Plugin 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
Simplifying Theme Functionality
Streamlining functions.php

Plugin 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
Reducing Theme Options

                                              Less is more.




46       WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Reducing Theme Options

Plugin Territory
The following options are functional, rather than presentational, and therefore
should be left to Plugins:
F a v ic o n




 47                         WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Reducing Theme Options

Plugin Territory
The following options are functional, rather than presentational, and therefore
should be left to Plugins:
Favicon
G o o g le A n a ly t ic s




 48                         WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Reducing Theme Options

Plugin Territory
The following options are functional, rather than presentational, and therefore
should be left to Plugins:
Favicon
Google Analytics
S E O M e t a Ta g s




 49                         WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Reducing Theme Options

Plugin Territory
The following options are functional, rather than presentational, and therefore
should be left to Plugins:
Favicon
Google Analytics
SEO Meta Tags
R o b o ts .tx t




 50                         WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Reducing Theme Options

Plugin Territory
The following options are functional, rather than presentational, and therefore
should be left to Plugins:
Favicon
Google Analytics
SEO Meta Tags
Robots.txt
D 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
Simplifying Theme Functionality
Reducing Theme Options

Plugin Territory
The following options are functional, rather than presentational, and therefore
should be left to Plugins:
Favicon
Google Analytics
SEO Meta Tags
Robots.txt
Disabling the Admin Toolbar
G 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 g
r e s o u r c e s /c o n t e n t




 52                         WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Reducing Theme Options

Plugin Territory
The following options are functional, rather than presentational, and therefore
should be left to Plugins:
Favicon
Google Analytics
SEO Meta Tags
Robots.txt
Disabling the Admin Toolbar
GZipping/compressing/minimizing resources/content
R 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
Simplifying Theme Functionality
Reducing Theme Options

Plugin Territory
The following options are functional, rather than presentational, and therefore
should be left to Plugins:
Favicon
Google Analytics
SEO Meta Tags
Robots.txt
Disabling the Admin Toolbar
GZipping/compressing/minimizing resources/content
Replacing core-bundled scripts with CDN-hosted versions


Child Theme Territory
The following options are ideal candidates for customization via Child Theme
rather than via Theme options:
C us to m C S S
 54                         WordCamp Kansas City: 02 June 2012
General Clean-Up of Theme Files

                                  Pruning to stay healthy




55        WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
General Clean-Up of Theme Files
U n n e e d e d Te m p l a t e F i l e s
U 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
Simplifying Theme Functionality
General Clean-Up of Theme Files
Unneeded Template Files
Unmodified template files (archive.php, author.php, category.php, date.php,
tag.php, etc.). DRY

U n n e e d e d Te m p l a t e - P a r t F i l e s
M 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
Simplifying Theme Functionality
General Clean-Up of Theme Files
Unneeded Template Files
Unmodified template files (archive.php, author.php, category.php, date.php,
tag.php, etc.). DRY

Unneeded Template-Part Files
Minimally 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
Simplifying Theme Functionality
General Clean-Up of Theme Files
Unneeded Template Files
Unmodified template files (archive.php, author.php, category.php, date.php,
tag.php, etc.). DRY

Unneeded Template-Part Files
Minimally modified template-part files (searchform.php)


Unneeded Development Files
__MACOSX


U 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
Unneeded Callbacks/Functions

     Purposeful derivatives of Twenty Ten and Twenty Eleven




60                WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Unneeded Callbacks/Functions

Comment List Callback
function twentyeleven_comment( $comment, $args, $depth ) {}




 61                     WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Unneeded Callbacks/Functions

Comment List Callback
function twentyeleven_comment( $comment, $args, $depth ) {}


Consider using the default comment-list walker:
// D e f a u l t o u t p u t
w p _l i s t _c o m m e n t s ( ) ;




 62                           WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality
Unneeded Callbacks/Functions

Comment List Callback
function twentyeleven_comment( $comment, $args, $depth ) {}


Consider using the default comment-list walker:

// Default output
wp_list_comments();

// S p l i t C o m m e n t s a n d P i n g s
w 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
Simplifying Theme Functionality
Unneeded Callbacks/Functions

Comment List Callback
function twentyeleven_comment( $comment, $args, $depth ) {}


Consider using the default comment-list walker:

// Default output
wp_list_comments();

// Split Comments and Pings
wp_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
Simplifying Theme Functionality
Unneeded Callbacks/Functions

Content Filters
If you don't 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 r
v a lu e is 4 0
f 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
Simplifying Theme Functionality
Unneeded Callbacks/Functions

Content Filters
If you don't need it, just remove it:
// Custom excerpt length. Default value is 55; Filter value is 40
function 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
Simplifying Theme Functionality
Unneeded Callbacks/Functions

Content Filters
If you don't need it, just remove it:
// Custom excerpt length. Default value is 55; Filter value is 40
function 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 t
v 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
Simplifying Theme Functionality
Unneeded Callbacks/Functions

Content Filters
If you don't need it, just remove it:
// Custom excerpt length. Default value is 55; Filter value is 40
function 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 e
y o u r o w n G a lle r y C S S
a 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
Feedback

     You’ve heard from me; now I want to hear from you




69           WordCamp Kansas City: 02 June 2012
Simplifying Theme Functionality




                 Questions?



 70                WordCamp Kansas City: 02 June 2012

Weitere ähnliche Inhalte

Was ist angesagt?

Building GPE: What We Learned
Building GPE: What We LearnedBuilding GPE: What We Learned
Building GPE: What We Learnedrajeevdayal
 
So, you want to be a plugin developer?
So, you want to be a plugin developer?So, you want to be a plugin developer?
So, you want to be a plugin developer?ylefebvre
 
PHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudZendCon
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i TutorialZendCon
 
Converting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 ThemeConverting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 ThemeAdolfo Nasol
 
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to DevelopmentWordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to DevelopmentEvan Mullins
 
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!Evan Mullins
 
What book and journal publishers need to know to get accessibility right
What book and journal publishers need to know to get accessibility rightWhat book and journal publishers need to know to get accessibility right
What book and journal publishers need to know to get accessibility rightApex CoVantage
 
Html5 tutorial for beginners
Html5 tutorial for beginnersHtml5 tutorial for beginners
Html5 tutorial for beginnersSingsys Pte Ltd
 
Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)Chinmoy Mohanty
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4Hal Stern
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4Hal Stern
 
PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)kuydigital
 
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...Eric Sembrat
 

Was ist angesagt? (16)

Building GPE: What We Learned
Building GPE: What We LearnedBuilding GPE: What We Learned
Building GPE: What We Learned
 
So, you want to be a plugin developer?
So, you want to be a plugin developer?So, you want to be a plugin developer?
So, you want to be a plugin developer?
 
PHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the Cloud
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i Tutorial
 
Converting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 ThemeConverting (X)HTML/CSS template to Drupal 7 Theme
Converting (X)HTML/CSS template to Drupal 7 Theme
 
guadec-2007
guadec-2007guadec-2007
guadec-2007
 
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to DevelopmentWordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
 
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
 
Zend Framework
Zend FrameworkZend Framework
Zend Framework
 
What book and journal publishers need to know to get accessibility right
What book and journal publishers need to know to get accessibility rightWhat book and journal publishers need to know to get accessibility right
What book and journal publishers need to know to get accessibility right
 
Html5 tutorial for beginners
Html5 tutorial for beginnersHtml5 tutorial for beginners
Html5 tutorial for beginners
 
Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4
 
PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)PSD to a Drupal Theme (using a base theme)
PSD to a Drupal Theme (using a base theme)
 
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
October 2016 - USG Rock Eagle - Everything You Need to Know to Plan Your Drup...
 

Ähnlich wie WordCamp KC 2012: Simplifying Theme Functionality

[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress DevelopmentAdam Tomat
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPressNile Flores
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - LondonMarek Sotak
 
Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Adam Tomat
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress WebsitesKyle Cearley
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Paul Bearne
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28thChris Adams
 
Jquery tutorial
Jquery tutorialJquery tutorial
Jquery tutorialBui Kiet
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011David Carr
 
Ilivanov Alexander.How to make best theme.DrupalCamp Kyiv 2011
Ilivanov Alexander.How to make best theme.DrupalCamp Kyiv 2011Ilivanov Alexander.How to make best theme.DrupalCamp Kyiv 2011
Ilivanov Alexander.How to make best theme.DrupalCamp Kyiv 2011camp_drupal_ua
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWP Engine UK
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWP Engine
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's CodeWildan Maulana
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practicesmarkparolisi
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1Yoav Farhi
 
Using RequireJS with CakePHP
Using RequireJS with CakePHPUsing RequireJS with CakePHP
Using RequireJS with CakePHPStephen Young
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolmentRajib Ahmed
 

Ähnlich wie WordCamp KC 2012: Simplifying Theme Functionality (20)

[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
 
D7 theming what's new - London
D7 theming what's new - LondonD7 theming what's new - London
D7 theming what's new - London
 
Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019Supercharging WordPress Development - Wordcamp Brighton 2019
Supercharging WordPress Development - Wordcamp Brighton 2019
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28th
 
Jquery tutorial
Jquery tutorialJquery tutorial
Jquery tutorial
 
20110820 header new style
20110820 header new style20110820 header new style
20110820 header new style
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
 
Ilivanov Alexander.How to make best theme.DrupalCamp Kyiv 2011
Ilivanov Alexander.How to make best theme.DrupalCamp Kyiv 2011Ilivanov Alexander.How to make best theme.DrupalCamp Kyiv 2011
Ilivanov Alexander.How to make best theme.DrupalCamp Kyiv 2011
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
Using RequireJS with CakePHP
Using RequireJS with CakePHPUsing RequireJS with CakePHP
Using RequireJS with CakePHP
 
Starting with PHP and Web devepolment
Starting with PHP and Web devepolmentStarting with PHP and Web devepolment
Starting with PHP and Web devepolment
 

Kürzlich hochgeladen

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Kürzlich hochgeladen (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

WordCamp KC 2012: Simplifying Theme Functionality

  • 1. Simplifying Theme Functionality Chip Bennett, WordCamp Kansas City, 02 June 2012 @chip_bennett
  • 2. Simplifying Theme Functionality Audience: Developers New and Derivative Themes Why Simplify? De-crappifying header.php Streamlining functions.php Reducing Theme Options General Clean-Up of Theme Files Unneeded 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 Einstein 3 WordCamp Kansas City: 02 June 2012
  • 4. Simplifying Theme Functionality Why Simplify? T h e m e M a in t e n a n c e & S u p p o r t S 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 Functionality Why Simplify? Theme Maintenance & Support Simplifying 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 n S 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 Functionality Why Simplify? Theme Maintenance & Support Simplifying Theme functionality will facilitate maintenance, Plugin Support/Integration Simplifying Theme functionality will facilitate out-of-the-box C h ild T h e m e s S 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 what's there doesn't really need to be there 7 WordCamp Kansas City: 02 June 2012
  • 8. Simplifying Theme Functionality De-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 Functionality De-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 your echo '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 Functionality De-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 Functionality De-Crappifying header.php RSS Feed Links <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS 2.0 Feed" href="<?php bloginfo('rss2_url'); ?>" /> <link rel="alternate" type="text/xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss_url'); ?>" /> <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('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 Functionality De-Crappifying header.php RSS Feed Links functions.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 Functionality De-Crappifying header.php Script 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, we'll come back to this slide later.) 13 WordCamp Kansas City: 02 June 2012
  • 14. Simplifying Theme Functionality De-Crappifying header.php Script and Stylesheet Links functions.php: Scripts function 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 Functionality De-Crappifying header.php Script and Stylesheet Links Protip: wp_enqueue_scripts() $deps parameter function 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 Functionality De-Crappifying header.php Script and Stylesheet Links Protip: wp_enqueue_scripts() $deps parameter function 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() will enqueue it automatically! No need to call wp_enqueue_script( 'jquery' ): 16 WordCamp Kansas City: 02 June 2012
  • 17. Simplifying Theme Functionality De-Crappifying header.php Script and Stylesheet Links Protip: wp_enqueue_scripts() $deps parameter function 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() will enqueue 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 Functionality De-Crappifying header.php Script and Stylesheet Links functions.php: Stylesheets 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' ); } add_action( 'wp_enqueue_scripts', 'themename_enqueue_styles' ); 18 WordCamp Kansas City: 02 June 2012
  • 19. Simplifying Theme Functionality De-Crappifying header.php Script and Stylesheet Links header.php <?php wp_head(); ?> 19 WordCamp Kansas City: 02 June 2012
  • 20. Simplifying Theme Functionality De-Crappifying header.php IE 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() doesn't have a parameter for IE conditionals... 20 WordCamp Kansas City: 02 June 2012
  • 21. Simplifying Theme Functionality De-Crappifying header.php IE Conditional Stylesheets Enter 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 Functionality De-Crappifying header.php IE Conditional Stylesheets functions.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 Functionality De-Crappifying header.php IE Conditional Stylesheets functions.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' ); // IE7 PROTIP: Possibly coming soon to a wp_enqueue_script() near you. See Trac ticket #16024 23 WordCamp Kansas City: 02 June 2012
  • 24. Simplifying Theme Functionality De-Crappifying header.php IE Conditional Stylesheets header.php <?php wp_head(); ?> 24 WordCamp Kansas City: 02 June 2012
  • 25. Simplifying Theme Functionality De-Crappifying header.php Comment-Reply Script <?php if ( comments_open() && is_singular() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } ?> Okay, this one's not bad. But it calls wp_enqueue_script(), so we should put it in our script-enqueueing callback in functions.php, right? 25 WordCamp Kansas City: 02 June 2012
  • 26. Simplifying Theme Functionality De-Crappifying header.php Comment-Reply Script <?php if ( comments_open() && is_singular() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } ?> Okay, this one's not bad. But it calls wp_enqueue_script(), so we should put 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 Functionality De-Crappifying header.php Comment-Reply Script Meet the 'comment_form_before' action hook 27 WordCamp Kansas City: 02 June 2012
  • 28. Simplifying Theme Functionality De-Crappifying header.php Comment-Reply Script Meet the 'comment_form_before' action hook functions.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 Functionality De-Crappifying header.php Comment-Reply Script Meet the 'comment_form_before' action hook functions.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 Functionality De-Crappifying header.php Comment-Reply Script header.php // Silence is golden comments.php <?php comment_form(); ?> 30 WordCamp Kansas City: 02 June 2012
  • 31. Simplifying Theme Functionality De-Crappifying header.php <?php body_class(); ?> <?php $bodyclass = ''; // Generic semantic classes if ( 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 Functionality De-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 Functionality De-Crappifying header.php <?php body_class(); ?> header.php <body <?php body_class(); ?> 33 WordCamp Kansas City: 02 June 2012
  • 34. Simplifying Theme Functionality De-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 Functionality De-Crappifying header.php Plugin 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 Theme 36 WordCamp Kansas City: 02 June 2012
  • 37. Simplifying Theme Functionality Streamlining functions.php Callback 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 Functionality Streamlining functions.php Callback 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 Functionality Streamlining functions.php Callback 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 Functionality Streamlining functions.php Callback all the things Before register_sidebar( array( // Args array ) ); 40 WordCamp Kansas City: 02 June 2012
  • 41. Simplifying Theme Functionality Streamlining functions.php Callback 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 Functionality Streamlining functions.php Plugin 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 Functionality Streamlining functions.php Plugin 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 Functionality Streamlining functions.php Plugin 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 Functionality Streamlining functions.php Plugin 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 Functionality Reducing Theme Options Plugin Territory The following options are functional, rather than presentational, and therefore should be left to Plugins: F a v ic o n 47 WordCamp Kansas City: 02 June 2012
  • 48. Simplifying Theme Functionality Reducing Theme Options Plugin Territory The following options are functional, rather than presentational, and therefore should be left to Plugins: Favicon G o o g le A n a ly t ic s 48 WordCamp Kansas City: 02 June 2012
  • 49. Simplifying Theme Functionality Reducing Theme Options Plugin Territory The following options are functional, rather than presentational, and therefore should be left to Plugins: Favicon Google Analytics S E O M e t a Ta g s 49 WordCamp Kansas City: 02 June 2012
  • 50. Simplifying Theme Functionality Reducing Theme Options Plugin Territory The following options are functional, rather than presentational, and therefore should be left to Plugins: Favicon Google Analytics SEO Meta Tags R o b o ts .tx t 50 WordCamp Kansas City: 02 June 2012
  • 51. Simplifying Theme Functionality Reducing Theme Options Plugin Territory The following options are functional, rather than presentational, and therefore should be left to Plugins: Favicon Google Analytics SEO Meta Tags Robots.txt D 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 Functionality Reducing Theme Options Plugin Territory The following options are functional, rather than presentational, and therefore should be left to Plugins: Favicon Google Analytics SEO Meta Tags Robots.txt Disabling the Admin Toolbar G 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 g r 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 Functionality Reducing Theme Options Plugin Territory The following options are functional, rather than presentational, and therefore should be left to Plugins: Favicon Google Analytics SEO Meta Tags Robots.txt Disabling the Admin Toolbar GZipping/compressing/minimizing resources/content R 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 Functionality Reducing Theme Options Plugin Territory The following options are functional, rather than presentational, and therefore should be left to Plugins: Favicon Google Analytics SEO Meta Tags Robots.txt Disabling the Admin Toolbar GZipping/compressing/minimizing resources/content Replacing core-bundled scripts with CDN-hosted versions Child Theme Territory The following options are ideal candidates for customization via Child Theme rather 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 healthy 55 WordCamp Kansas City: 02 June 2012
  • 56. Simplifying Theme Functionality General Clean-Up of Theme Files U n n e e d e d Te m p l a t e F i l e s U 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 Functionality General Clean-Up of Theme Files Unneeded Template Files Unmodified template files (archive.php, author.php, category.php, date.php, tag.php, etc.). DRY U n n e e d e d Te m p l a t e - P a r t F i l e s M 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 Functionality General Clean-Up of Theme Files Unneeded Template Files Unmodified template files (archive.php, author.php, category.php, date.php, tag.php, etc.). DRY Unneeded Template-Part Files Minimally 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 Functionality General Clean-Up of Theme Files Unneeded Template Files Unmodified template files (archive.php, author.php, category.php, date.php, tag.php, etc.). DRY Unneeded Template-Part Files Minimally modified template-part files (searchform.php) Unneeded Development Files __MACOSX U 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 Eleven 60 WordCamp Kansas City: 02 June 2012
  • 61. Simplifying Theme Functionality Unneeded Callbacks/Functions Comment List Callback function twentyeleven_comment( $comment, $args, $depth ) {} 61 WordCamp Kansas City: 02 June 2012
  • 62. Simplifying Theme Functionality Unneeded Callbacks/Functions Comment List Callback function twentyeleven_comment( $comment, $args, $depth ) {} Consider using the default comment-list walker: // D e f a u l t o u t p u t w p _l i s t _c o m m e n t s ( ) ; 62 WordCamp Kansas City: 02 June 2012
  • 63. Simplifying Theme Functionality Unneeded Callbacks/Functions Comment List Callback function twentyeleven_comment( $comment, $args, $depth ) {} Consider using the default comment-list walker: // Default output wp_list_comments(); // S p l i t C o m m e n t s a n d P i n g s w 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 Functionality Unneeded Callbacks/Functions Comment List Callback function twentyeleven_comment( $comment, $args, $depth ) {} Consider using the default comment-list walker: // Default output wp_list_comments(); // Split Comments and Pings wp_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 Functionality Unneeded Callbacks/Functions Content Filters If you don't 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 r v a lu e is 4 0 f 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 Functionality Unneeded Callbacks/Functions Content Filters If you don't need it, just remove it: // Custom excerpt length. Default value is 55; Filter value is 40 function 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 Functionality Unneeded Callbacks/Functions Content Filters If you don't need it, just remove it: // Custom excerpt length. Default value is 55; Filter value is 40 function 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 t v 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 Functionality Unneeded Callbacks/Functions Content Filters If you don't need it, just remove it: // Custom excerpt length. Default value is 55; Filter value is 40 function 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 e y o u r o w n G a lle r y C S S a 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 you 69 WordCamp Kansas City: 02 June 2012
  • 70. Simplifying Theme Functionality Questions? 70 WordCamp Kansas City: 02 June 2012