'How to automatically: WordPress permalink settings set via a plug-in, after the "plugins_loaded" action

By selecting the desired persistent connection structure:

Which is like this: http://localhost/%postname%/

Thanks to the following code of WordPress,

<? php add_action ('plugins_loaded', 'function_name'); ?>

I expect the above persistent connection settings to update itself automatically every time.

For this, we need to login to the admin panel and save the settings each time. But isn't there a way to automate it?



Solution 1:[1]

After a long period of research and testing, the results are very satisfactory. It successfully adjusts as you wish and works properly. Excellent.

function reset_permalinks() 
{
    global $wp_rewrite;

    $wp_rewrite->set_permalink_structure( '/%postname%/' );
}
add_action( 'plugins_loaded', 'reset_permalinks' );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1