【问题标题】:WP Redirect function not working on live siteWP 重定向功能在实时站点上不起作用
【发布时间】:2019-02-18 22:31:54
【问题描述】:

我在 localhost 上尝试了这段代码:

<?php wp_redirect('https://google.com/'); exit; ?>

在本地主机上运行良好。

当我在现场上传时,它的功能 wp_redirect 不起作用。

感谢您的帮助。

【问题讨论】:

  • 请说明您的本地主机和生产环境(服务器、PHP 版本等)之间的环境差异
  • PHP 和 Wordpress 版本相同
  • 何时重定向页面?

标签: wordpress redirect


【解决方案1】:

你应该把这个函数放在代码的顶部。 我建议你使用 init action 来重定向页面。

add_action('init', function(){
if( isset($_GET['exit']) ) {
wp_redirect('https://google.com/');
 exit;
}
});

此代码将 functions.php 放入您的主题中。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-09-07
  • 2019-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-14
  • 2020-03-01
  • 1970-01-01
相关资源
最近更新 更多