Do WordPress Core Filenames Work as Hooks?

This is in reference to another answer here on wordpress.stackexchange. The answerer used the filename as the hook to enqueue scripts and styles to certain pages.

add_action( 'admin_print_scripts-post-new.php', 'portfolio_admin_script', 11 );
add_action( 'admin_print_scripts-post.php', 'portfolio_admin_script', 11 );

1
1

The short answer is ‘yes’.

Taken from this article the suffix of those ‘screen specific hooks’ is given by:

  • For custom admin pages added via add_menu_page() – including settings pages – (and related functions) it is the screen ID (the value returned by add_menu_page())
  • For the admin page listing posts of any post type, it is edit.php
  • On the ‘add new’ page of any post type, it is post-new.php
  • On the edit page of any post type, it is post.php
  • For taxonomy pages it is edit-tags.php

You may find this plug-in useful, developed by @Kaiser, based on the article linked to above.

Leave a Comment