Custom Templates Anyone?

This is horrible, not the code itself but what it does. Found in a theme, this little snippet was used to completely replace the default Page Template drop down in WordPress (replace, not add to).

Note that this is only the template drop down part. There was also a whole custom meta box registered that this code was used in. It’s the concept I wanted to share with you more than the code itself.

<p>
<label for="template_name">
	<?php _e('Select Template', TEXTDOMAIN); ?>
</label>
</p>
<p>
<select name="template_name" id="template_name">
	<option value="about" <?php selected($template, 'about'); ?>><?php _e('About', TEXTDOMAIN); ?></option>
	<option value="blog" <?php selected($template, 'blog'); ?>><?php _e('Blog', TEXTDOMAIN); ?></option>
	<option value="contact" <?php selected($template, 'contact'); ?>><?php _e('Contact', TEXTDOMAIN); ?></option>
	<option value="page" <?php selected($template, 'page'); ?>><?php _e('Page', TEXTDOMAIN); ?></option>
	<option value="portfolio" <?php selected($template, 'portfolio'); ?>><?php _e('Portfolio', TEXTDOMAIN); ?></option>
</select>
</p>

One of the things you should NEVER do in a theme (sometimes plugins can do this) is completely remove or disable default WordPress behavior. By removing the default Page Templates option, this theme completely broke any plugins that might have leveraged that for custom templates created in the theme. The theme developers also dramatically increased their own workload by doing this.

Submitted by Anthony Hortin.

Advertisements

5 thoughts on “Custom Templates Anyone?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s