Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on a plugin that creates a custom post type and I would like to display a custom template without modifying the theme.

Here's the simplified code I'm working with:

add_filter('template_include', 'my_custom_template');

function my_custom_template($incFile) {
    global $wp;
    global $wp_query;

    if ($wp->query_vars['post_type'] == 'custom-post-type') {

        $incFile = MY_PLUGIN_TEMPLATES . '/template.php';

    }

    return $incFile;

} 

The problem I'm running into is that when allow_url_include is turned off in a server's php.ini file, this throws a fun little error:

Warning: include() [function.include]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in http://path\to\wp-includes\template-loader.php on line 43

So I guess the question is, is there a way to send a template through the template_include filter without triggering this allow_url_include error?

Thanks!

share|improve this question
    
Wouldn't ya know - 10 minutes or less since I asked my question and I've discovered the answer. I was attempting to define MY_PLUGIN_TEMPLATES using plugins_dir_url(), now it looks like this: define( 'MY_PLUGIN_TEMPLATES', WP_PLUGIN_DIR . '/my_plugin/templates' ); And all is well. –  bybloggers Jun 22 '11 at 23:21
1  
I always set the plugin path using the following code: dirname( __FILE__ ) - It will allow the name of the plugin directory to be changed without modifying the code. –  mfields Jun 23 '11 at 1:50
    
Thanks, just updated it using that. –  bybloggers Jun 23 '11 at 23:58
add comment

1 Answer

Wouldn't ya know - 10 minutes or less since I asked my question and I've discovered the answer.

I was attempting to define MY_PLUGIN_TEMPLATES using using plugins_dir_url(), now it looks like this and is working:

define( 'MY_PLUGIN_TEMPLATES', dirname( __FILE__ ) . '/templates' );

Thanks to mfields for the suggestion of dirname instead of WP_PLUGIN_DIR.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.