【问题标题】:WP - wp_rewrite page 404WP - wp_rewrite 页面 404
【发布时间】:2015-09-18 09:16:00
【问题描述】:

如果页面正在使用某个页面主题,则使用 $wp_rewrite 更改永久链接。

导致首页出现 404 错误,并且在管理页面中运行良好。

//Change permalink to subject
function change_permalink_themebasis( $post ) {
    $template = get_post_meta( $post->ID, '_wp_page_template' ,true );
    if ( 'page-branches.php' == $template) {
        global $wp_rewrite; 
        $wp_rewrite->page_structure = $wp_rewrite->root . 'branches/%pagename%/'; 
    } elseif ( 'page-modules.php' == $template) {
        global $wp_rewrite; 
        $wp_rewrite->page_structure = $wp_rewrite->root . 'modules/%pagename%/'; 
    } else{
        global $wp_rewrite; 
        $wp_rewrite->page_structure = $wp_rewrite->root . '%pagename%/'; 
    }
}
add_action( 'add_meta_boxes_page', 'change_permalink_themebasis' );

如何解决这个问题?我认为问题在于 add_action 类型“add_meta_boxes_page”,但我找不到合适的。

编辑: Oke 发现它与以下代码有关:

$wp_rewrite->page_structure = $wp_rewrite->root . 'branches/%pagename%/'; 

【问题讨论】:

    标签: php wordpress templates permalinks slug


    【解决方案1】:

    只需转到设置 -> 固定链接,滚动到底部并点击保存更改

    【讨论】:

    • 在编写指导性答案时,澄清是王道 - 或许可以解释一下为什么会这样?
    • 是的,这行不通。 Normaly 这确实有效,因为在保存时它会重写.htaccess。但是有了这个脚本就不行了。幸运的是,它是 2017 年,我在 2015 年解决了这个问题。(不记得如何)感谢您的评论。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    • 2012-07-10
    • 2020-02-09
    • 1970-01-01
    • 2023-01-01
    • 1970-01-01
    相关资源
    最近更新 更多