Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/joeydi/image-bg-position/archive/refs/heads/main.zipA WordPress plugin for setting a focus point on media library images. The focus point is applied as object-position on images rendered with wp_get_attachment_image(), so object-fit: cover crops keep the important part of the image in frame.
Forked from the original, unmaintained plugin by florianmatthias.
Usage
- Open an image in the media library (the modal or the attachment edit screen).
- Under Focus Point, click Set.
- Click the image, or type X/Y percentages. The crop previews update as you go.
- Click Save (or press Enter). Press Esc or Cancel to discard changes.
In the media modal the value saves right away. On the attachment edit screen it saves when you click Update.
Reset puts the focus point back in the center.
How it works
- The value is stored in the
bg_pos_desktoppost meta as"X% Y%", e.g."32% 41%". A centered focus point (50% 50%) deletes the meta. - The
wp_get_attachment_image_attributesfilter appendsobject-position:X% Y%to the image'sstyleattribute. - To use the value somewhere else, such as a CSS background, read the meta directly:
$position = get_post_meta( $attachment_id, 'bg_pos_desktop', true ) ?: '50% 50%';
Installation
Copy this directory to wp-content/plugins/image-bg-position/ and activate it.
Upgrading from the original 1.0 plugin: the main file was renamed from image-bg-postion.php to image-bg-position.php, so WordPress deactivates the plugin when you update. Reactivate it afterwards. Saved focus points are kept because the bg_pos_desktop meta key didn't change.
Changelog
See CHANGELOG.md.
License
GPLv3 or later. See LICENSE.