Skip to main content
page not post
Source Link
Nathan Johnson
  • 6.5k
  • 6
  • 30
  • 49

You can use get_current_screen() to get details about the current screen. We want to hook on or after load-edit.php because get_current_screen() is defined just prior to this hook.

By hooking into load-edit.php, we guarantee that this code will only fire on the edit.php page. Then we check the current screen to see if the post type is a page. If it is, then we enqueue the script.

add_action( 'load-edit.php', 'wpse_259909_load_edit' );
function wpse_259909_load_edit() {
  if( 'page' === get_current_screen()->post_type ) {
    add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );
  }
}

function gp_front_page_script() {
  wp_enqueue_script(
    'gp_fp', 
    plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
    array( 'jquery' )
  );
}

If you need the script on the individual edit pages, you can add this hook too.

add_action( 'load-page.php', 'wpse_259909_load_edit' );

If you need the script on the new edit pages, you can add this hook too.

add_action( 'load-page-new.php', 'wpse_259909_load_edit' );

I'm not sure why the above code isn't working for you. I added the above code to a blank plugin on a fresh install of WP 4.7.3 and it enqueues the javascript in the head after jQuery.

The load-edit.php fires pretty early in the request, so maybe you're adding the hook too late.

You can use get_current_screen() in the admin_enqueue_scripts hook as well, but you need to make sure you're on an edit screen. So this should work too.

add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );    
function gp_front_page_script() {
  $current_screen = get_current_screen();
  if( 'edit' === $current_screen->base>parent_base && 'page' === $current_screen->post_type ) {
    wp_enqueue_script(
      'gp_fp', 
      plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
      array( 'jquery' )
    );
  }
}

You can use get_current_screen() to get details about the current screen. We want to hook on or after load-edit.php because get_current_screen() is defined just prior to this hook.

By hooking into load-edit.php, we guarantee that this code will only fire on the edit.php page. Then we check the current screen to see if the post type is a page. If it is, then we enqueue the script.

add_action( 'load-edit.php', 'wpse_259909_load_edit' );
function wpse_259909_load_edit() {
  if( 'page' === get_current_screen()->post_type ) {
    add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );
  }
}

function gp_front_page_script() {
  wp_enqueue_script(
    'gp_fp', 
    plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
    array( 'jquery' )
  );
}

If you need the script on the individual edit pages, you can add this hook too.

add_action( 'load-page.php', 'wpse_259909_load_edit' );

I'm not sure why the above code isn't working for you. I added the above code to a blank plugin on a fresh install of WP 4.7.3 and it enqueues the javascript in the head after jQuery.

The load-edit.php fires pretty early in the request, so maybe you're adding the hook too late.

You can use get_current_screen() in the admin_enqueue_scripts hook as well, but you need to make sure you're on an edit screen. So this should work too.

add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );    
function gp_front_page_script() {
  $current_screen = get_current_screen();
  if( 'edit' === $current_screen->base && 'page' === $current_screen->post_type ) {
    wp_enqueue_script(
      'gp_fp', 
      plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
      array( 'jquery' )
    );
  }
}

You can use get_current_screen() to get details about the current screen. We want to hook on or after load-edit.php because get_current_screen() is defined just prior to this hook.

By hooking into load-edit.php, we guarantee that this code will only fire on the edit.php page. Then we check the current screen to see if the post type is a page. If it is, then we enqueue the script.

add_action( 'load-edit.php', 'wpse_259909_load_edit' );
function wpse_259909_load_edit() {
  if( 'page' === get_current_screen()->post_type ) {
    add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );
  }
}

function gp_front_page_script() {
  wp_enqueue_script(
    'gp_fp', 
    plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
    array( 'jquery' )
  );
}

If you need the script on the individual edit pages, you can add this hook too.

add_action( 'load-page.php', 'wpse_259909_load_edit' );

If you need the script on the new edit pages, you can add this hook too.

add_action( 'load-page-new.php', 'wpse_259909_load_edit' );

I'm not sure why the above code isn't working for you. I added the above code to a blank plugin on a fresh install of WP 4.7.3 and it enqueues the javascript in the head after jQuery.

The load-edit.php fires pretty early in the request, so maybe you're adding the hook too late.

You can use get_current_screen() in the admin_enqueue_scripts hook as well, but you need to make sure you're on an edit screen. So this should work too.

add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );    
function gp_front_page_script() {
  $current_screen = get_current_screen();
  if( 'edit' === $current_screen->parent_base && 'page' === $current_screen->post_type ) {
    wp_enqueue_script(
      'gp_fp', 
      plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
      array( 'jquery' )
    );
  }
}
add a bit and copyedit
Source Link
Nathan Johnson
  • 6.5k
  • 6
  • 30
  • 49

You can use get_current_screen() to get details about the current screen. We want to hook on or after load-edit.php because get_current_screen() is defined just prior to this hook.

By hooking into load-edit.php, we guarantee that this code will only fire on the edit.php page. Then we check the current screen to see if the post type is a page. If it is, then we enqueue the script.

add_action( 'load-edit.php', 'wpse_259909_load_edit' );
function wpse_259909_load_edit() {
  if( 'page' === get_current_screen()->post_type ) {
    add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );
  }
}

function gp_front_page_script() {
  wp_enqueue_script(
    'gp_fp', 
    plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
    array( 'jquery' )
  );
}

If you need the script on the individual edit pages, you can add this hook too.

add_action( 'load-page.php', 'wpse_259909_load_edit' );

I'm not sure why the above code isn't working for you. I added the above code to a blank plugin on a fresh install of WP 4.7.3 and it enqueues the javascript in the head after jQuery.

The load-edit.php fires pretty early in the request, so maybe you're adding the hook too late.

You can use get_current_screen() in the admin_enqueue_scripts hook as well, but you need to make sure you're on an edit screen. So this should work too.

add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );    
function gp_front_page_script() {
  $current_screen = get_current_screen();
  if( 'edit' === $current_screen->base && 'page' === $current_screen->post_type ) {
    wp_enqueue_script(
      'gp_fp', 
      plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
      array( 'jquery' )
    );
  }
}

You can use get_current_screen() to get details about the current screen. We want to hook on or after load-edit.php because get_current_screen() is defined just prior to this hook.

By hooking into load-edit.php, we guarantee that this code will only fire on the edit.php page. Then we check the current screen to see if the post type is a page. If it is, then we enqueue the script.

add_action( 'load-edit.php', 'wpse_259909_load_edit' );
function wpse_259909_load_edit() {
  if( 'page' === get_current_screen()->post_type ) {
    add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );
  }
}

function gp_front_page_script() {
  wp_enqueue_script(
    'gp_fp', 
    plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
    array('jquery')
  );
}

If you need the script on the individual edit pages, you can add this hook too.

add_action( 'load-page.php', 'wpse_259909_load_edit' );

You can use get_current_screen() to get details about the current screen. We want to hook on or after load-edit.php because get_current_screen() is defined just prior to this hook.

By hooking into load-edit.php, we guarantee that this code will only fire on the edit.php page. Then we check the current screen to see if the post type is a page. If it is, then we enqueue the script.

add_action( 'load-edit.php', 'wpse_259909_load_edit' );
function wpse_259909_load_edit() {
  if( 'page' === get_current_screen()->post_type ) {
    add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );
  }
}

function gp_front_page_script() {
  wp_enqueue_script(
    'gp_fp', 
    plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
    array( 'jquery' )
  );
}

If you need the script on the individual edit pages, you can add this hook too.

add_action( 'load-page.php', 'wpse_259909_load_edit' );

I'm not sure why the above code isn't working for you. I added the above code to a blank plugin on a fresh install of WP 4.7.3 and it enqueues the javascript in the head after jQuery.

The load-edit.php fires pretty early in the request, so maybe you're adding the hook too late.

You can use get_current_screen() in the admin_enqueue_scripts hook as well, but you need to make sure you're on an edit screen. So this should work too.

add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );    
function gp_front_page_script() {
  $current_screen = get_current_screen();
  if( 'edit' === $current_screen->base && 'page' === $current_screen->post_type ) {
    wp_enqueue_script(
      'gp_fp', 
      plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
      array( 'jquery' )
    );
  }
}
added 209 characters in body; added 148 characters in body
Source Link
Nathan Johnson
  • 6.5k
  • 6
  • 30
  • 49

You can use get_current_screen() to get details about the current screen. We want to hook on or after load-edit.php because get_current_screen() is defined just prior to this hook.

By hooking into load-edit.php, we guarantee that this code will only fire on the edit.php page. Then we check the current screen to see if the post type is a page. If it is, then we enqueue the script.

add_action( 'load-edit.php', 'wpse_259909_load_edit' );
function wpse_259909_load_edit() {
  if( 'page' === get_current_screen()->post_type ) {
    add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );
  }
}

function gp_front_page_script() {
  wp_enqueue_script(
    'gp_fp', 
    plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
    array('jquery')
  );
}

If you need the script on the individual edit pages, you can add this hook too.

add_action( 'load-page.php', 'wpse_259909_load_edit' );

You can use get_current_screen() to get details about the current screen. We want to hook on or after load-edit.php because get_current_screen() is defined just prior to this hook.

add_action( 'load-edit.php', 'wpse_259909_load_edit' );
function wpse_259909_load_edit() {
  if( 'page' === get_current_screen()->post_type ) {
    add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );
  }
}

function gp_front_page_script() {
  wp_enqueue_script(
    'gp_fp', 
    plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
    array('jquery')
  );
}

You can use get_current_screen() to get details about the current screen. We want to hook on or after load-edit.php because get_current_screen() is defined just prior to this hook.

By hooking into load-edit.php, we guarantee that this code will only fire on the edit.php page. Then we check the current screen to see if the post type is a page. If it is, then we enqueue the script.

add_action( 'load-edit.php', 'wpse_259909_load_edit' );
function wpse_259909_load_edit() {
  if( 'page' === get_current_screen()->post_type ) {
    add_action( 'admin_enqueue_scripts', 'gp_front_page_script' );
  }
}

function gp_front_page_script() {
  wp_enqueue_script(
    'gp_fp', 
    plugins_url() . '/network-plugins/includes/globals/genpages/front-page.js',
    array('jquery')
  );
}

If you need the script on the individual edit pages, you can add this hook too.

add_action( 'load-page.php', 'wpse_259909_load_edit' );
Source Link
Nathan Johnson
  • 6.5k
  • 6
  • 30
  • 49
Loading