更新页面链接-WordPress

时间:2018-11-15 05:47:18

标签: wordpress

我想通过wordpress编辑此链接

http://domain-name.com/self-coaching-tips/media/ 

当我单击“编辑”时,我只能编辑“媒体”部分。我想将整个链接更新为

http://domain-name.com/media/ 

我该怎么做?

enter image description here

1 个答案:

答案 0 :(得分:0)

添加到您的functions.php文件中:

function cstm_url_redirects() {
    $redirect_rules = array(
        array('old'=>'/self-coaching-tips/media/','new'=>'/media/'),
        //array('old'=>'/some-other-old/page/','new'=>'/some/new/page/'),
    );
    foreach( $redirect_rules as $rule ) :
        // if URL of request matches with the one from the array, then redirect
        if( urldecode($_SERVER['REQUEST_URI']) == $rule['old'] ) :
            wp_redirect( site_url( $rule['new']) , 301 );
            exit();
        endif;
    endforeach;
}

add_action('template_redirect', 'cstm_url_redirects');

更多示例here