我正在尝试有条件地在我的一个客户页面上运行实时聊天服务的脚本,因为当实时聊天不断弹出时,在页面上工作很烦人。
我一直试图通过我的子主题的functions.php 来实现这一点。我决定使用 WP 钩子“WP_Footer”将脚本注入它通常会加载的位置。不幸的是,当我将代码添加到文件中时,我的网站崩溃并显示错误“www.hakimlaw.com 当前无法处理此请求。HTTP 错误 500”。
function my_cond_scripts()
if ( is_user_logged_in() ) {
echo '<p>Your script will not run here!</p>';
} else {
echo '<p>Your script will run here!</p>';
}
add_action('wp_footer', 'my_cond_scripts');
我希望使用 echo 我可以使用网络检查器来检查代码是否正确且有条件地传递。任何输入将不胜感激!
HTTP 500 错误是由代码中的语法问题引起的。缺少左括号和右括号。这应该有效:
function my_cond_scripts()
{
if ( is_user_logged_in() ) {
echo '<p>Your script will not run here!</p>';
} else {
echo '<p>Your script will run here!</p>';
}
}
add_action('wp_footer', 'my_cond_scripts');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句