我相信有一种更优雅的方式来实现你的愿望,然而这种方法确实有效。刚刚测试过。
/**
 * Redirect pages from array.
 *
 * @author Michael Ecklund
 * @author_url https://www.michaelbrentecklund.com/
 *
 * @return void
 */
function redirect_pages() {
    // Page from => Page to
    $redirect_pages = array(
        \'wordpresspage\' => \'/wordpress-page\'
    );
    // Check all required redirections.
    foreach( $redirect_pages as $page_from => $page_to ) {
        // Check the current page.
        if( is_page( $page_from ) ) {
            // Redirect to proper page.
            wp_redirect( site_url( $page_to ), 301 );
            exit;
        }
    }
}
 为了正确触发重定向,您需要为“wordpresspage”添加一个页面,以便它能够正确检测当前页面并重定向到
domain.com/wordpress-page/.
添加动作以触发挂钩。
add_action( \'template_redirect\', \'redirect_pages\' );