Using WordPress ‘image_align_input_fields()’ PHP function

The image_align_input_fields() WordPress PHP function retrieves HTML for the image alignment radio buttons with the specified one checked.

Usage

image_align_input_fields($post, $checked = '');

Parameters

  • $post (WP_Post) – The post object.
  • $checked (string) – The alignment that should be checked. Optional, default: ”.

More information

See WordPress Developer Resources: image_align_input_fields

Examples

Display Image Alignment Options

Display image alignment options for a post with ID 10.

$post = get_post(10);
$alignment_options = image_align_input_fields($post);
echo $alignment_options;

Pre-select ‘Center’ Alignment

Pre-select the ‘center’ alignment option for a post with ID 10.

$post = get_post(10);
$alignment_options = image_align_input_fields($post, 'center');
echo $alignment_options;

Pre-select ‘Left’ Alignment

Pre-select the ‘left’ alignment option for a post with ID 20.

$post = get_post(20);
$alignment_options = image_align_input_fields($post, 'left');
echo $alignment_options;

Display Alignment Options in a Custom Form

Display image alignment options for a post with ID 30 in a custom form.

$post = get_post(30);
$alignment_options = image_align_input_fields($post);
?>
<form action="process.php" method="post">
    <?php echo $alignment_options; ?>
    <input type="submit" value="Submit">
</form>

Display Alignment Options with a Custom Checked Value

Display image alignment options for a post with ID 40 and a custom checked value.

$post = get_post(40);
$checked = get_post_meta($post->ID, 'custom_alignment', true);
$alignment_options = image_align_input_fields($post, $checked);
echo $alignment_options;