do_action( ‘add_meta_boxes’, string $post_type, WP_Post $post )

Fires after all built-in meta boxes have been added.

Parameters

$post_typestring
Post type.
$postWP_Post
Post object.

More Information

The hook allows meta box registration for any post type.

Passes two parameters: $post_type and $post.

Note: You can also use add_meta_boxes_{post_type} for best practice, so your hook will only run when editing a specific post type. This will only receive 1 parameter – $post.

Source

do_action( 'add_meta_boxes', $post_type, $post );

Changelog

VersionDescription
3.0.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    Example migrated from Codex:

    Example usage:

    function adding_custom_meta_boxes( $post_type, $post ) {
        add_meta_box( 
            'my-meta-box',
            __( 'My Meta Box' ),
            'render_my_meta_box',
            'post',
            'normal',
            'default'
        );
    }
    add_action( 'add_meta_boxes', 'adding_custom_meta_boxes', 10, 2 );

    Example with a post-type specific call:

    function adding_custom_meta_boxes( $post ) {
        add_meta_box( 
            'my-meta-box',
            __( 'My Meta Box' ),
            'render_my_meta_box',
            'post',
            'normal',
            'default'
        );
    }
    add_action( 'add_meta_boxes_post', 'adding_custom_meta_boxes' );

    Both will accomplish the same thing. Best practice is to use add_meta_boxes_{post-type} to create less unnecessary hooks for other post types.

  2. Skip to note 4 content

    this note is to provide feedback for the documentation

    the following code will produce an error in PHP >= 7
    PHP Fatal Error: Uncaught Type Error: Argument #2 ($post) must be of type WP_Post, WP_Comment given
    if I try to edit a comment navigating to
    /wp-admin/comment.php?action=editcomment&c=COMMENT_ID

    it seems that the hook is fired with objects of type WP_Comment as well

    add_action( 'add_meta_boxes', function( string $post_type, WP_Post $post ): void {} );

You must log in before being able to contribute a note or feedback.