How could I execute my plugin just in frontend (not in backend)

I don’t need my plugin running through wp-admin, including wp-login. How could I prevent it? is_admin works fine but i don’t know how to ignore everything related to wp-admin (like wp-login.php).
Thanks.

Related posts

Leave a Reply

2 comments

  1. Check the requested URI:

    if(!is_admin()
     && strpos($_SERVER['REQUEST_URI'], 'wp-login.php') === false 
     && strpos($_SERVER['REQUEST_URI'], 'wp-signup.php') === false) { ... }
    

    But it’s probably better to use a white-list style:

    if(is_front_page() || is_singular() || is_archive()) { ... }

    These 3 tags should cover pretty much all of the front-end…

  2. function start() {
      if( is_admin() == true ) {
        require_once plugin_dir_path( __FILE__ ) . 'includes/backend/backend-init.php';
      } else {
          require_once plugin_dir_path( __FILE__ ) . 'includes/frontend/frontend-init.php';
      }
    }
      
    function runit(){
      add_action('init','start');
    }
    runit();
    

    one will work on the frontend, and the other on the backend respectively.