Why aren't some plugin styles loading when I load a template?

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

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?

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?

Share Improve this question edited Aug 6, 2019 at 7:41 Pikamander2 asked Aug 6, 2019 at 7:33 Pikamander2Pikamander2 6287 silver badges20 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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;
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745266498a4619488.html

相关推荐

  • Why aren't some plugin styles loading when I load a template?

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

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信