I’ve added some codes to my theme’s function so when I activated the theme, it will update the category base, permalinks, and post_per_page, and they worked perfectly fine.

However, since I’m just begging to learn how to code, I’d like to know if I’m doing it the right way, or maybe any of you know a better and the correct way of updating WordPress options to avoid multiple occurrences.

Here is the code I’m using:

// Category base
if (get_option('category_base') == '') {
update_option( 'category_base', 'genre' );
}
else { update_option( 'category_base', 'genre' ); 
}

// Permalinks
if (get_option('permalink_structure') == '') {
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure('/%postname%/');
}
else    {
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure('/%postname%/');
}

// Post Per Page
if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {
    update_option( 'posts_per_page', 40 );
}

Read more here: What is the correct way of updating wordpress options


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: