Plugin Directory

Changeset 3236642


Ignore:
Timestamp:
02/07/2025 02:11:58 PM (14 months ago)
Author:
wpcompany
Message:

Adding function for background-postion

Location:
media-focus-point
Files:
7 added
2 edited

Legend:

Unmodified
Added
Removed
  • media-focus-point/trunk/media-focus-point.php

    r3216407 r3236642  
    106106
    107107    add_action( 'admin_enqueue_scripts', 'wpcmfp_media_focus_point_admin_scripts' );
    108    
    109    
     108
     109    //Add the background-position to the style of an element
     110    function MFP_Background( $attachment_id, $include_image = true ) {
     111        // Get the stored background position
     112        $bg_pos_desktop = get_post_meta( $attachment_id, 'bg_pos_desktop', true );
     113
     114        // Default background position if not set
     115        if ( empty( $bg_pos_desktop ) ) {
     116            $bg_pos_desktop = '50% 50%';
     117        }
     118
     119        // Start building the style
     120        $style = 'background-position: ' . esc_attr( $bg_pos_desktop ) . ';';
     121
     122        // Include background-image if enabled
     123        if ( $include_image ) {
     124            $image_url = wp_get_attachment_url( $attachment_id );
     125            if ( $image_url ) {
     126                $style = 'background-image: url(' . esc_url( $image_url ) . '); ' . $style . ' background-size: cover;';
     127            }
     128        }
     129
     130        return $style;
     131    }
  • media-focus-point/trunk/readme.txt

    r3216446 r3236642  
    55Tested up to: 6.7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.2.2
     7Stable tag: 1.2.1
    88License: GPLv3 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2121== Installation ==
    2222
     23If you installed the plugin and set a focus point on the image **it should work right away**.
     24Most WordPress themes already use this standard WordPress method to render featured images.
     25
    2326To display an image in your custom template with the focus point applied, you can use the following code snippet:
    24 Most WordPress themes already use this standard WordPress method to render featured images.
    2527
    2628**For featured images (post thumbnails):**
     
    2931        echo get_the_post_thumbnail('', 'full');
    3032    ?>
     33
     34**For background images:**
     35
     36    <div class="myelement" style="<?= MFP_Background($image_id, false); ?>"></div>
    3137
    3238
     
    7985== Changelog ==
    8086
     87= 1.3 =
     88* New function MFP_Background to dynamically generate background position for background images.
     89
    8190= 1.2.2 =
    8291* Remove the disabled script that caused errors in certain situations
Note: See TracChangeset for help on using the changeset viewer.