maybe_redirect_404

函式
maybe_redirect_404 ( No parameters )

maybe_redirect_404: 這是WordPress中的一個函式,允許你在請求的頁面沒有找到時將使用者重定向到一個404頁面: 這個函式檢查請求的頁面是否存在,如果不存在,它將使用者重定向到一個404頁面。

糾正了定義NOBLOGREDIRECT時的404重定向。

function maybe_redirect_404() {
	if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) ) {
		/**
		 * Filters the redirect URL for 404s on the main site.
		 *
		 * The filter is only evaluated if the NOBLOGREDIRECT constant is defined.
		 *
		 * @since 3.0.0
		 *
		 * @param string $no_blog_redirect The redirect URL defined in NOBLOGREDIRECT.
		 */
		$destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT );

		if ( $destination ) {
			if ( '%siteurl%' === $destination ) {
				$destination = network_home_url();
			}

			wp_redirect( $destination );
			exit;
		}
	}
}

常見問題

FAQs
檢視更多 >