如何通过编码在Wordpress中重定向页面

时间:2016-09-15 03:34:35

标签: php wordpress

我正在使用WordPress的二十九主题。我在那里创建了一个页面模板。在那里我创建了一个登录表单。我想在成功登录后将用户重定向到下一页。

我试过了:

header('Location: http://website.com/my-page/');
wp_redirect(get_page_by_title('My Page'));

说错误

  已发送

标头

3 个答案:

答案 0 :(得分:0)

页面模板不适合编写重定向。尝试使用适当的钩子将您的重定向逻辑放在functions.php中。

<?xml version="1.0" encoding="UTF-8"?>
-<root>
-<data>
<message>This summer both Stephen Curry & Kevin Durant toured Asia,   
connecting with fans & inspiring young athletes.  »    
http://on.nba.com/2bWpo3L  » http://on.nba.com/29LfO6X</message>

<story>Golden State Warriors added 4 new photos.</story>

<created_time>2016-09-15T01:03:28+0000</created_time>

<id>47657117525_10154616463827526</id>

</data>
-<data>

<message>The worlds of sports & tech came together once again as Stephen   
Curry attended TechCrunch Disrupt in San Francisco. #TCDisrupt</message>

<created_time>2016-09-14T23:21:38+0000</created_time>

<id>47657117525_10154616220367526</id>

</data>
-<data>

<message>All Summer 16. #DubNation</message>

<created_time>2016-09-14T18:42:15+0000</created_time>

<id>47657117525_10154615411837526</id>

</data>
-<data>

<message></message>

<story>Golden State Warriors shared Draymond Green's photo.</story>

<created_time>2016-09-14T18:29:31+0000</created_time>

<id>47657117525_10154615388222526</id>

</data>
-<data>

<message>Single game tickets are now available for Warriors Insiders! »    
http://on.nba.com/17O7eLP</message>

<created_time>2016-09-14T17:10:00+0000</created_time>

<id>47657117525_10154613058837526</id>

</data>
-<data>

<message>Signs that training camp is almost here... </message>

<story>Golden State Warriors added 2 new photos.</story>

<created_time>2016-09-14T01:41:40+0000</created_time>

<id>47657117525_10154613158592526</id>

</data>

-<paging>
<previous>https://graph.facebook.com/v2.7/47657117525/feed?
access_token.......</previous>
<next>https://graph.facebook.com/v2.7/47657117525/feed?   
 access_token=......</next>
</paging>
</root>

如果您在页面加载后必须重定向,请改用Javascript。

答案 1 :(得分:0)

检查该文件是否包含没有BOM编码的UTF-8,并且您不打印浏览器。

答案 2 :(得分:0)

您可以通过javascript重定向页面来解决此问题

echo '<script type="text/javascript">window.location = "/my-page/"</script>';
exit;