SLB: Registering Themes

By Sol in Lab

Note: This information is out of date.  Please see the latest information on registering theme’s for Simple Lightbox.

Progress continues on enabling themes (née templates) in Simple Lightbox.  After a quick finalization of the theme structure, I moved onto adding the necessary API hooks to allow anyone to register a theme to be used by SLB.

What does this mean?

In short, it means that users will be able to create and share new themes just like WordPress plugins (in fact, they will be distributed as WP plugins).  In addition, templates will also be able to register custom themes so that the lightbox will integrate perfectly with the theme.

Nice.

How is it done?

I couldn’t keep the Simple in the name if using SLB wasn’t simple, and registering themes is no exception.  2 simple steps is all it takes:

  1. Hook into slb_init_themes– This ensures that SLB is activated and ready for themes to be registered
    add_action('slb_init_themes', 'my_custom_theme');
  2. Register the theme using slb_register_theme()
    slb_register_theme($name, $title, $stylesheet_url, $layout);

All together now:

add_action('slb_init_themes', 'my_custom_theme');

function my_custom_theme() {
    $name = 'cool_theme';
    $title = 'Cool';
    $stylesheet_url = '[URL to CSS file goes here]';
    $layout = '[layout html goes here]';
    slb_register_theme($name, $title, $stylesheet_url, $layout);
}

Once a theme is registered, it will be selectable from the admin options.  This is the final part that I will be wiring up tomorrow, so if all goes well, I’m hoping to have a new version to release by tomorrow!

So go make some themes!  (Check out yesterday’s post for more information on theme layouts).