Using WordPress ‘get_compat_media_markup()’ PHP function

The get_compat_media_markup WordPress PHP function generates HTML markup for the attachment details and edit buttons in the media library.

Usage

get_compat_media_markup( $attachment_id, $args = null );

Parameters

  • $attachment_id (int) (Required) – The ID of the attachment for which the markup should be generated.
  • $args (array) (Optional) – An array of arguments that can be used to customize the generated markup. Default: null

More information

See WordPress Developer Resources: get_compat_media_markup

Examples

Display attachment details and edit buttons for an image

This example generates and displays the attachment details and edit buttons for an image with the ID of 123.

// Get the attachment markup
$attachment_markup = get_compat_media_markup( 123 );

// Display the attachment markup
echo $attachment_markup['item'];

Display attachment details and edit buttons for an audio file

This example generates and displays the attachment details and edit buttons for an audio file with the ID of 456.

// Get the attachment markup
$attachment_markup = get_compat_media_markup( 456 );

// Display the attachment markup
echo $attachment_markup['item'];

Customize the attachment details and edit buttons

This example generates and displays the attachment details and edit buttons for an attachment with the ID of 789, using custom arguments.

// Define custom arguments
$args = array(
    'send' => false,
    'delete' => false,
    'compat' => false,
);

// Get the attachment markup
$attachment_markup = get_compat_media_markup( 789, $args );

// Display the attachment markup
echo $attachment_markup['item'];

Display the attachment details without edit buttons

This example generates and displays the attachment details without edit buttons for an attachment with the ID of 321.

// Define custom arguments
$args = array(
    'send' => false,
    'delete' => false,
    'compat' => false,
);

// Get the attachment markup
$attachment_markup = get_compat_media_markup( 321, $args );

// Display the attachment details
echo $attachment_markup['item'];

Display the attachment details with only the delete button

This example generates and displays the attachment details with only the delete button for an attachment with the ID of 654.

// Define custom arguments
$args = array(
    'send' => false,
    'delete' => true,
    'compat' => false,
);

// Get the attachment markup
$attachment_markup = get_compat_media_markup( 654, $args );

// Display the attachment details
echo $attachment_markup['item'];