WordPress Themes

Read These

Child Themes

  • Don’t make changes to parent theme, create a child instead.
  • But if many changes are made, may be best to make parent theme, to avoid future code depreciation.

Child Themes Process

  • Create a new folder in wp-content/themes
  • Best Practice: Same name as parent with -child appended.
  • Create style.css
    [php]
    /*
    Theme Name: Twenty Thirteen Child
    Theme URI: http://example.com
    Description:
    Author:
    Author URI:
    Template: twentythirteen
    Version: 0.1.0
    */
    [/php]
    • Must at least include Theme name and Template, the latter being that of the parent theme directory.
  • Create a functions.php file
    • Does not overwrite, instead loaded in addition to parent theme functions.php.
    • Loaded before parent theme.
  • Inherit Styles
    • Don’t have to do this if you want to write CSS from them ground up, just keeping the same base template.
    • @import url (“../twentythirteen/style.css”);
  • Add Template Files
    • Best Practice: Copy the parent theme template file and make modifications in child theme.
    • Useful Plugins: What the File, What Template File Am I Viewing?, and Debug Bar.
  • Including Other Files
    • Must include the directory path when accessing other files.
      <?php require_once( get_stylesheet_directory() . ‘/my_included_file.php’ ); ?>
      <img src=”?php echo get_stylesheet_directory_uri(); ?>/images/mypicture.png”>
  • Enqueue Styles and Scripts
    • Each should be enqueued in its own function.
    • add_action( ‘wp_enqueue_scripts’, ‘my_plugin_add_stylesheet’ );
      function my_plugin_add_stylesheet() {
      wp_enqueue_style( ‘my-style’, get_stylesheet_directory_uri() . ‘/style.css’, false, ‘1.0’, ‘all’ );
  • Using add_theme_support to add additional post-formats overwrites the parent themes enabled formats, not add.