WordPress.org

Support

Support » Plugins and Hacks » Problem with template_redirect

Problem with template_redirect

  • Hello; I have written a plugin that loads a different template if a variable “tpl” is set in the url :

    <?php
    /*
    Plugin Name: Template Changer
    Description: Having a specific template if $_REQUEST[‘tpl’] is set.
    Author: Gordie (based upon the script by Kaf Oseo)
    Version: 3
    */
    function template_changer() {
    if ($_REQUEST[‘tpl’]) {
    $tpl_file = TEMPLATEPATH . “/” . $_REQUEST[‘tpl’] . ‘.php’;
    if ( file_exists($tpl_file) ) {
    include($tpl_file);
    }else{
    return;
    }
    }else{
    return;
    }
    }

    if (!is_admin()) {
    add_action(‘template_redirect’, ‘template_changer’);
    }
    ?>

    The template loads since it doesn’t display anything if the content of my tpl (popup.php actually) is
    <?php exit;?>

    But If I put a real template code;
    It does not work :
    For example; If I duplicate the content of the template “single” (just changing the main class; to check if it works); It shows the page twice : once with popup.php and the other with the regular single template !!!

    How can I do ?

Viewing 1 replies (of 1 total)
  • This reply’s a little late, but it may help others: Once you’ve loaded your custom template, instead of “return” you need “exit”.

    – Tim

Viewing 1 replies (of 1 total)
  • The topic ‘Problem with template_redirect’ is closed to new replies.
Skip to toolbar