• I design/develop custom themes and I would like to add image alignment as an option for featured images.

    I prefer not to use a plugin to accomplish this.

    Basically, I want to have an align dropdown option for featured images. I would then create CSS classes so if center was selected the image would appear above the post heading in the category listing page, left image align would wrap the heading and excerpt around the featured image.

    Is there code I could add to the functions.php file to accomplish this?

    Alternatively, could I add code that would detect an image’s proportions and apply an appropriate alignment automatically? For example, if the image was wide and narrow it would be centered above the post heading, if the image was not as wide or a square left align would be used by default.

    Any feedback is MUCH appreciated!

Viewing 1 replies (of 1 total)
  • Please be aware that it is up to the theme to decide what to do with the featured image. The only part the editor plays is to make the association of a specific image with a specific post.
    The editor should do things that are specific to the post.
    The theme should do things that are unifying for all the posts on the site.

    The theme could have one option in the Customizer of how to treat all featured images.
    Or the theme could have a post meta input in the editor to store that option for each featured image. How that is implemented is different for each editor. And storing options per post is a hassle for the user, especially one with lots of content (whether it was written before or after the start of using your theme).

    There are WordPress functions that use the image width and height to generate the proper srcset attributes for responsive image handling. The theme does not know the device width at the time of generating the page output however.

Viewing 1 replies (of 1 total)
  • The topic ‘Featured image alignment choices in WP editor’ is closed to new replies.