Only version with Init hook interface?

I am trying to create a function in my topic that relies on doing things before sending headers. So naturally, I hooked the Init hook like this:

add_action('init', 'my_function');

But the problem is that I want my_function to run if the user is not looking at the admin section or login page.

So which hook I can use is only an interface, but is executed before the headers are sent. If you look at the API link , it does not seem to exist, and, obviously, the conditions do not work at the beginning of execution.

So besides finding the URLs / wp-admin / and / wp-login / (which seems awkward to me), I cannot understand.

+5
source share
3 answers

if(!is_admin()){}

:

if(!is_admin()) {
  //Style
  add_action('init', 'style');

  function style()
  {
      wp_enqueue_style('style', THEMEROOT . '/css/your.css');
  }
}
+6

. wp , , , , , .

<?php
function my_function() {
    if ( ! is_admin() && ! is_login_page() ) {
        // Enqueue scripts, do theme magic, etc.
    }
}

add_action( 'wp', 'my_function' );

function is_login_page() {
    return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
}

: , ( wp_head... !). , send_headers:

function my_function() {
    if ( 'index.php' == $GLOBALS['pagenow'] ) {
        // Pre-header processing on the front-end
    }
}

add_action( 'wp_loaded', 'my_function' );

-, , , . , , .

+2

, , .

function my_func(){
 if ( !is_admin())
 {

 // add code here for show only in front-end or create another function outside this block and call that function here.
 }
 else
 {
 // add code here for show only in admin or create another function outside this block and call that function here.
}}add_action ('init', 'my_func');

, .

+1

All Articles