How to redirect template in wp plugin ?

by Nuke07
2 replies
Hey Guys,

I've developed a plugin, in which from home page user should redirect to upsell page once submit an optin form.

I'm using following function to load home page template:
PHP Code:
add_action('template_redirect''pluginInit'5);
function 
pluginInit()
{
    
    global 
$post_type;
    
$post_type get_query_var('post_type'); //getting the value of post_type(variable key) from global wp_query class
    
    
    
if($post_type == 'sqplugin')
    {
        if (
file_exists(TEMPLATEPATH '/single-' $post_type '.php')) return; //file_exists checks whether a file or dir exists.
                
load_template(WP_PLUGIN_DIR '/sqplugin' .'/home-page.php'); //This function is a wp ver. of require()
                
                           
        
exit;
    }
    
 

This is url for home page:
PHP Code:
http://localhost/Keithy2/sqplugin/testing/ 
On Placing aff-page.php in action of optin form, url changes to:
PHP Code:
http://localhost/Keithy2/sqplugin/testing/aff-page.php 
aff-page.php appearing in url, and template doesn't load with backend plugin values.

Kindly advice, how do i change the template from home page to aff page without changing url.

Url should remain:
PHP Code:
http://localhost/Keithy2/sqplugin/testing/ 
Thanks in Advance

Best Regards

Nuke
#plugin #redirect #template

Trending Topics