WP Manifestindependent plugin directory
manifest / media / image-bg-position

Image Background Focus Position

WordPress plugin: set a focus point on media library images, applied as object-position

★ 0stars

Install

Download source zip No release zip yet

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.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

A 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

  1. Open an image in the media library (the modal or the attachment edit screen).
  2. Under Focus Point, click Set.
  3. Click the image, or type X/Y percentages. The crop previews update as you go.
  4. 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_desktop post meta as "X% Y%", e.g. "32% 41%". A centered focus point (50% 50%) deletes the meta.
  • The wp_get_attachment_image_attributes filter appends object-position:X% Y% to the image's style attribute.
  • 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.