0

I'm using template_redirect to load custom template files based on the URL:

add_action( 'template_redirect', function()
{
    if (is_singular('business'))
    {
        load_template(get_plugin_path() . 'templates/business.php');
    }
});

It works for the most part, but a few CSS files don't appear to be loading. Specifically, Elementor Pro's frontend.min.css file isn't loading even though some of its other files are. That messes up some of the styles on my site.

What causes this to happen, and how can I fix it?

1 Answer 1

1

According to the WordPress Codex, using template_redirect to load a different template is discouraged and can cause certain code to not be executed, which of course can result in strange bugs.

template_include is the more appropriate solution. It loads a template file but without the behavior mentioned above.

add_action( 'template_include', function($original_template)
{
    if (is_singular('business'))
    {
        load_template(get_plugin_path() . 'templates/business.php');
    }

    return $original_template;
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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