3

functions.php でパーマリンク設定を変更して (子テーマで 2012 に)、手動で何もせずにアクティブにして機能させるにはどうすればよいですか?

このコードは機能するはずですが、機能していないようです..何かを見逃していると思います。

if($run_when_theme_is_activated_and_user_wants_this_permalink_structure){
        global $wp_rewrite;
        $wp_rewrite->set_permalink_structure( '/%postname%/' );
        $wp_rewrite->flush_rules();
}

「パーマリンク設定」ページにアクセスすると... wp-admin/options-permalink.php 実際、「投稿名」はすでに選択されており、テストすると機能します。したがって、保存する必要はありません。この特定のページにアクセスするだけです。パーマリンク設定に手動でアクセスする必要があるステップは、ソリューションではスキップする必要があります。

4

2 に答える 2

1

このコードを使用します。それは 100% 動作します。ありがとう

/**
 * Rewrite set up, when theme activate i mean
 */
if (isset($_GET['activated']) && is_admin()) {
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure('/%postname%/');
    $wp_rewrite->flush_rules();
}

/**
* Redirect to Permalink setting Page.
* Otherwise Redirect rule will not work Properly.
*/
function redirect_to_permalink() {

    wp_redirect('options-permalink.php');
}
add_action( 'after_switch_theme', 'redirect_to_permalink' );
于 2017-08-31T05:49:14.250 に答える