Quick note working with child themes and Wordpress

Continuing my adventures in the world of Wordpress theming today, I stumbled across a minor gotcha when working with Child Themes and writing code using functions.

When you're using Dimas Begunoff's WPAlchemy framework for making metaboxes, the code examples refer to creating a sample meta box like so:


  $custom_metabox = new WPAlchemy_MetaBox(array
  (
    'id' => '_custom_meta', // underscore prefix hides fields from the custom fields area
    'title' => 'My Custom Meta',
    'template' => TEMPLATEPATH . '/custom/simple_meta.php',
  ));

This won't work with child themes, because the TEMPLATEPATH will be pointing to the template path of the parent theme. As all your code is (or should be...) in the child theme, you won't be able to get to the template.

You need STYLESHEETPATH

If you're using a child theme, you'll need to use a different constant instead, called STYLESHEETPATH, which rather confusingly gives you the equivalent path, for the child theme:


  $custom_metabox = new WPAlchemy_MetaBox(array
  (
    'id' => '_custom_meta', // underscore prefix hides fields from the custom fields area
    'title' => 'My Custom Meta',
    'template' => STYLESHEETPATH . '/custom/simple_meta.php',
  ));

Found via nabble.



Copyright © 2020 Chris Adams
Powered by Cryogen
Theme by KingMob