Update permalinks if not set at the time of plugin activation

I need permalink to be set different from default after the plugin is activated
I used get_option(‘permalink_structure’) to check if permalink already set or not…

Here is the code block used in plugin activation function , I used class structure

Read More
 if (get_option('permalink_structure'))
    {
        $this->setRewriteRules();
        global $wp_rewrite;
        $wp_rewrite->flush_rules(true);
    }

and here is the serRewriteRules function

function setRewriteRules()
{
    add_rewrite_rule('plugin-url/$', '/wp-content/plugins/my-plugin/page.php', 'top');
}

I searched a lot and update my code so many time but still not working for me ….

Related posts

Leave a Reply

1 comment

  1. rather than changing permalink dynamically you can use generate link from WP permalinks function

    for e.g.

    get_the_permalink()
    the_permalink()
    get_post_type_archive_link()