Support » Requests and Feedback » Hook naming inconsistency, support for custom post types

  • There is a naming inconsistency with the following hooks. I suggest they all have the wp_ prefix. Also I suggest that there be specific hooks for custom post types. For example, how can I hook my function to the deletion of my custom post type?

    add_action(‘save_post’, ‘custom_save_function’);

    add_action(‘wp_trash_post’, ‘custom_trash_function’);

    add_action(‘untrash_post’, ‘custom_restore_function’);

    add_action(‘delete_post’, ‘custom_delete_function’);

Viewing 1 replies (of 1 total)
  • Chris Olbekson


    Level 12 Bug Squasher & Forum Moderator

    There is no need for post type specific hooks. The post type can be filtered in the call back function.

    add_action( 'trashed_post', 'cpt_trash_post' );
    function cpt_trash_post( $post_id ) {
        if ( 'my_cpt_name' != get_post_type( $post_id ) )
         //Continue with your function

    This is how most WordPress hooks and filters are engineered. It’s common practice to do conditional checks in call back functions.

Viewing 1 replies (of 1 total)
  • The topic ‘Hook naming inconsistency, support for custom post types’ is closed to new replies.