我測驗了以下代碼將我的商店主頁重定向到另一個頁面,主頁。
它可以作業,但它也會將搜索結果重定向到主頁,這樣人們就看不到搜索結果。
add_action('template_redirect', 'bc_010101_redirect_woo_pages');
function bc_010101_redirect_woo_pages() {
if (is_shop())
{
wp_redirect('/');
exit;
}
}
如何解決?
uj5u.com熱心網友回復:
您可以將is_search()添加到 if 條件中,該條件確定查詢是否用于搜索。
所以你得到:
function action_template_redirect() {
/**
* is_shop() - Returns true when on the product archive page (shop).
* is_search() - Determines whether the query is for a search.
*
* (redirect to home)
*/
if ( is_shop() && ! is_search() ) {
wp_safe_redirect( home_url() );
exit;
}
}
add_action( 'template_redirect', 'action_template_redirect' );
或者作為產品搜索在 URL 中添加's'查詢變數,您可以嘗試使用:
function action_template_redirect() {
/**
* is_shop() - Returns true when on the product archive page (shop).
*
* (redirect to home)
*/
if ( is_shop() && ! isset( $_GET['s'] ) ) {
wp_safe_redirect( home_url() );
exit;
}
}
add_action( 'template_redirect', 'action_template_redirect' );
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/339495.html
標籤:WordPress的 重定向 求购
