How to redirect template in wp plugin ?

by 2 replies
3
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
#programming #plugin #redirect #template
  • Process the form using AJAX and replace the content on the page with the upsell content after they submit the form.
    • [1] reply
    • Hey Warrior,

      You're right we can process it using Ajax, but i was thinking if any wordpress function avaibale to do this.

      Thanks for your reply !!

Next Topics on Trending Feed