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 badges1 Answer
Reset to default 1According 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
评论列表(0条)