3 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
joedajigalo says

Hey,

I was wondering if someone can help me?

Is it possible to add a template page inside a plugin? Reason asking is, it would be easier for me to manage instead of adding the same template page to every theme.

Thanks! Joe.

3430 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

Hey,

I was wondering if someone can help me?

Is it possible to add a template page inside a plugin? Reason asking is, it would be easier for me to manage instead of adding the same template page to every theme.

Thanks! Joe.

yes http://stackoverflow.com/questions/4647604/wp-use-file-in-plugin-directory-as-custom-page-template

3 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
joedajigalo says

Hey!

Thanks for the link. I did try it out, but I might be lost at some code. The below is a sample of the code set up. I didn’t want to paste the whole code in the thread. Basically, I am using this:

add_action("template_redirect", 'my_theme_redirect');

function my_theme_redirect() {
    global $wp;
    $plugindir = dirname( __FILE__ );

    //A Specific Custom Post Type
    if ($wp->query_vars["pagename"] == 'Service') {
        $templatefilename = 'page-service.php';
            $return_template = $plugindir . '/themefiles/' . $templatefilename;
        do_theme_redirect($return_template);
    }
}

The plugin shows up and works perfectly (it’s a custom post type, not sure if this will make a difference).

But the page name “Service” is not showing in the drop down menu of “Add Page”. Here’s a quick snapshot of the coding:

\\Thanks Again! Joe.

3 posts
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
joedajigalo says

Hey Guys,

Ignore my 2nd post, I got it working. I supposed nothing is suppose to show up in the “Add Page” dropdown menu. Basically, it replaces a specific page. In this case, which I wanted to replace the post type archive page, and so here is the code that made it work:

//Template fallback
add_action("template_redirect", 'my_theme_redirect');

function my_theme_redirect() {
    global $wp;
    $plugindir = dirname( __FILE__ );

    //A Specific Custom Post Type
    if ($wp->query_vars["post_type"] == 'service') {
        $templatefilename = 'archive-service.php';
        if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) {
            $return_template = TEMPLATEPATH . '/' . $templatefilename;
        } else {
            $return_template = $plugindir . '/themefiles/' . $templatefilename;
        }
        do_theme_redirect($return_template);
    }
}

function do_theme_redirect($url) {
    global $post, $wp_query;
    if (have_posts()) {
        include($url);
        die();
    } else {
        $wp_query->is_404 = true;
    }
}

\\

Thanks! Joe.

10 posts
  • Has collected 1+ items on Envato Market
  • Has been part of the Envato Community for over 1 year
  • Sells items exclusively on Envato Market
  • Located in United States
Designer_17 says

How do you define which page it’s supposed to replace?

This is my code:

// Add callback to admin menu
add_action( 'template_redirect', 'uploadr_redirect' );

// Callback to add menu items
function uploadr_redirect() {

    global $wp;
    $plugindir = dirname( __FILE__ );

    // A Specific Custom Post Type
    if ( $wp->query_vars["post_type"] == 'uploadr' ) {

        $templatefilename = 'custom-uploadr.php';

        if ( file_exists( TEMPLATEPATH . '/' . $templatefilename )) {

            $return_template = TEMPLATEPATH . '/' . $templatefilename;

        } else {

            $return_template = $plugindir . '/themefiles/' . $templatefilename;

        }

        do_theme_redirect( $return_template );

    }

}

function do_theme_redirect( $url ) {

    global $post, $wp_query;

    if ( have_posts ()) {

        include( $url );
        die();

    } else {

        $wp_query->is_404 = true;

    }

}

as well as a page named uploadr. But I’m not seeing any change that I added in my custom-uploadr.php file.

PLEASE HELP!!! I’ve spent at least 8 hours reaserching this with no avail.

Thanks is andvance. ;)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by