Set WordPress settings programmatically

I am satisfied with Nikolay Yordanov’s answer. Just generalizing the solution.

Yes, we can update WordPress options programmatically. WordPress saves options in wp_options table. wp_options holds two rows option_name and option_value to store key and value respectively. We need right option_name and a way to save value in wp_options table.

As we know, we can update threaded comments option by going to wp-admin/options-discussion.php. By opening the page options-discussion.php in a code editor, you can easily found the required option_name to update.

WordPress Options-Discussion

Now, if one can get an option, also one can update it. What you need is WordPress function update_option.

Final PHP Snippet


function update_thread_comments_depth($depth){
    //Validation check
    if(is_int($depth) && 0 < $depth){

        update_option('thread_comments_depth', $width);

        return true; //success
    }

    return false; //failure
}

Hope, it will help to update other options as well, just open right file in code editor and find the required option name.

Leave a Comment

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino