Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

User customising position of WordPress Featured Image

You’re getting close on your second guess, but I think a better way would be to create your own custom field checkbox that displays in the existing featured image meta box. This makes the functionality nice and obvious from a usability perspective, and operates on a post by post basis as desired.

I put together the following code as a plugin, but for your purposes it sounds like you would want to add the following code(below my plugin comments) into your themes functions.php file, as the functionality seems like it would be more theme specific for you. Anyways, here’s what I put together:

<?php
/*
 * Plugin Name: Featured Image Toggle
 * Description: Adds a checkbox to your featured image meta box that you can use to customize how your featured image is displayed
 * Version: 1.0
 * Author: Ben HartLenn
 * Author URI: https://benhartlenn.com
 * License: N/A
 * Text Domain: featured-image-toggle
 */

// Enable featured images in theme, if they are NOT already enabled
if ( !current_theme_supports('post-thumbnails') ) {
    add_theme_support('post-thumbnails');
}

// Add checkbox custom field html to the bottom of the existing featured image meta box in post editor
add_filter('admin_post_thumbnail_html', 'fit_output_featured_image_checkbox', 10, 2);
function fit_output_featured_image_checkbox($content, $post_id) {
    $field_id = 'toggle_featured_image';
    $field_value = esc_attr(get_post_meta($post_id, $field_id, true));
    $field_text = esc_html__('Show Featured Image in Post Content.', 'featured-image-toggle');
    $field_state = checked($field_value, 1, false);

    $field_label = sprintf(
            '<p><label for="%1$s"><input type="checkbox" name="%1$s" id="%1$s" value="%2$s" %3$s> %4$s</label></p>', $field_id, $field_value, $field_state, $field_text
    );

    return $content .= $field_label;
}

// Save checkbox custom field data with value as 1 for checked, and 0 for unchecked
add_action('save_post', 'fit_save_featured_image_checkbox', 10, 3);
function fit_save_featured_image_checkbox($post_ID, $post, $update) {
    $field_id = 'toggle_featured_image';
    $field_value = isset($_REQUEST[$field_id]) ? 1 : 0;

    update_post_meta($post_ID, $field_id, $field_value);
}

// Prepend featured image to first paragraph of a posts content, if checkbox is checked, i.e. value == 1
add_filter('the_content', 'fit_insert_featured_image', 20);
function fit_insert_featured_image($content) {
    global $post;
    $featured_post_toggle = get_post_meta($post->ID, 'toggle_featured_image', true);

    if( has_post_thumbnail($post) && $featured_post_toggle == 1 ) {
        // NOTE: Adding 'medium' sized image to post content
        $content = preg_replace("/<p>/", "<p>" . get_the_post_thumbnail($post->ID, 'medium', ['class' => 'post-content-featured-image']), $content, 1);
        return $content;
    }
}

// If our checkbox is checked, also add a little css to float the image to the right, make the image 33% width of parent element, and thus make it responsive.
add_action( 'wp_head', 'fit_css');
function fit_css() {
    global $post;
    $featured_post_toggle = get_post_meta($post->ID, 'toggle_featured_image', true);

    if( is_singular('post') && $featured_post_toggle == 1 ) {
        echo '<style type="text/css">';
        // NOTE: Adjust the following css as wanted.
        echo 'img.post-content-featured-image { float: right; width: 33%; height: auto; margin: 0 0 2% 2%; }';
        echo '</style>';
    }
}

It sounds like you already have code, likely in your themes header.php file, that displays a posts featured image if it is set. You’ll want to modify that slightly to check if the checkbox we created above IS NOT checked before displaying the featured image normally, so your new code might look like this:

<?php
  $featured_post_toggle = get_post_meta($post->ID, 'toggle_featured_image', true);
  // $featured_post_toggle == 0 makes sure our checkbox is not checked
  if ( is_singular('post') && has_post_thumbnail() && $featured_post_toggle == 0 ) :
?>
    <div id="post-image">
      <?php the_post_thumbnail('large', ['class' => 'post-featured-image'] ); ?>
    </div>
<?php endif; ?>

As noted in my comments, you might need to adjust the css for featured images in post content, and you can pull in different sized featured images for when they are displayed in the post content.

Related Posts:

  1. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  2. Can I exclude a post by meta key using pre_get_posts function?
  3. Custom post meta field effect on the performance on the post
  4. How to get custom post meta using REST API
  5. Difference between meta keys with _ and without _ [duplicate]
  6. Orderby meta_value only returns posts that have existing meta_key
  7. What is the index [0] for on post meta fields?
  8. What is “meta_input” parameter in wp_insert_post() used for?
  9. How to enable revisions for post meta data?
  10. The “_encloseme” Meta-Key Conundrum
  11. Best way to programmatically remove a category/term from a post
  12. Using get_post_meta with new_to_publish
  13. Custom field metabox not showing in back-end
  14. So much data in postmeta
  15. Can I count the number of users matching a value in a multiple value key?
  16. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  17. How to hide meta box values from custom fields list?
  18. Auto sort the wp-admin post list by a meta key
  19. Move from old custom field to new post_thumbnails
  20. get_post_meta() unserialize issue – returns boolean(false)
  21. What is the advantage of the wp_options design pattern?
  22. Storing meta fields multiple times OR once with multi dimensional array?
  23. Allow user to create instances of custom field
  24. display specific custom fields
  25. Meta keywords and descriptions plugin for manually editing meta for each page/post
  26. Add options to featured image
  27. passing argument to get_template_part() or a better way to code
  28. Is it possible to store arrays in a custom field?
  29. Get updated meta data after save_post hook
  30. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  31. Save HTML formatted data to post meta using add_post_meta()
  32. importing data from non-wordpress mysql db
  33. Create meta boxes that don’t show in custom fields
  34. Transients vs CRON +Custom Fields: Caching Data Per Post
  35. Unable to save datetime custom meta field using update_post_meta() function
  36. Up/Down voting system for WordPress
  37. post meta data clearing on autosave
  38. Create custom field on post draft or publish?
  39. Display info from custom fields in all images’ HTML
  40. Ordering posts by anniversary using only day and month
  41. get_post_meta fields don’t show up on posts page
  42. Update meta values with AJAX
  43. How can I migrate all of my custom field thumbnails to the built-in post featured image?
  44. How to break meta values into different items and avoid duplicates?
  45. automatically set “Featured Image” the same as the og:i that is set in a custom field
  46. copy attachments to another post type and change attachment url
  47. Cannot edit post meta fields with rest API
  48. ajax delete value from custom field array
  49. Save attachment custom fields on front end
  50. How to use pagination with get_post_meta
  51. Copying Custom Meta Values from existing post to a duplicate post
  52. Add a post meta key and value only if it does not exist on the post
  53. Move value of one custom field to another
  54. Order posts according to user defined order for meta values?
  55. Adding a custom field or metabox to the post-thumbnail widget?
  56. Displaying posts with only upcoming dates according their custom field date value
  57. Custom fields to save multiple values
  58. Custom fields: In what order are they saved into the DB?
  59. Function to change meta value in database for each post
  60. Get a post_id where meta_value equals something in a serialized meta_value field
  61. Get aggregate list of all custom fields for entire blog
  62. Transition from (classical) serialized custom meta field to (gutenberg) rest enabled meta
  63. Unable to show ACF’s Image Custom Field properly in Genesis Framework [closed]
  64. Custom field value based on other custom field values
  65. wp_handle_upload error “Specified file failed upload test” but still creates attachment?
  66. How to save a ToggleControl value in a meta field?
  67. Which is best in the following scenario : post_meta vs custom table vs parent/child posts
  68. Saving custom image meta fields
  69. Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
  70. How to display Meta Field Value?
  71. Deleted pages showing up when querying for child pages
  72. MySQL query to set wp_postmeta using term_taxonomy_id value
  73. How to Validate Post Meta type/extension (Video File Image File etc)
  74. Get all meta keys assigned to a post type
  75. Add url from Custom Field as ‘Featured Image’. Code not working
  76. using multiple meta_key and meta_value in query_posts
  77. Custom Meta Box not Saving in Posts with Gutenberg Editor
  78. Adding custom fields (post meta) before/during wp_insert_post()
  79. Combine multiple custom field values into single value
  80. How can I sort homepage by a meta value?
  81. Get specific custom field keys from a post and put into an array
  82. How do I use wp_query for WordPress search?
  83. Nav Menu – Add class based on meta keys
  84. How to query posts with certain custom meta data, and output Post data
  85. MySQL Query that looks for post with Custom Field, then changes Category
  86. ACF: How to get the full field name (meta_key) by a field key?
  87. How to wrap meta values seperated by comma in ? [closed]
  88. Bulk remove post meta
  89. post meta getting deleted on save
  90. How to create html block to display extra information on woocommerce single product page
  91. Can’t get post ID using wp_insert_post_data
  92. Unique Post Meta Values
  93. Create Multiple File Upload Metabox in WordPress
  94. filtering custom post types via meta data drop down
  95. How to add a new meta key and assign timestamp to posts
  96. Run a check for multiple meta key values
  97. If meta key exists in get posts function otherwise create it
  98. Custom field not updating when value is empty
  99. meta_compare seems to be treating values as strings instead of integers as expected
  100. WordPress Rest API to call page data associate with custom meta
Categories custom-field Tags custom-field, post-meta, post-thumbnails
how to search everything
The Search FoRM Dilemma || The Search form Templating

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress