我添加了一个重定向功能,可以减慢我的网站速度。我可以在何时以及如何提前添加此操作以减少页面加载时间?
此处的代码:
add_action( 'template_redirect', 'my_page_template_redirect' );
function my_page_template_redirect()
{
if ( !is_user_logged_in() && !is_page(100)) {
wp_redirect( '/?page_id=100/');
}
}
答案 0 :(得分:0)
这个钩子是最适合重定向的钩子。但是,您可以做一件事来提高效率。 重定向后立即退出。通过执行此操作,页面将不会再加载并直接移至下一页。它会帮助你提高效率。这也是标准方式。来自codex的参考网址。 https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
add_action( 'template_redirect', 'my_page_template_redirect' );
function my_page_template_redirect()
{
if ( !is_user_logged_in() && !is_page(100)) {
wp_redirect( '/?page_id=100/');
exit(); // Place an exit here.
}
}