Skip to Content
Menu

post_exif()

Show the post EXIF metadata.

PHP July 20, 2017

Usage

PHP
nebula()->post_exif($icon)

Parameters

$icon
(Optional) (Boolean) Whether to show the icon.
Default: true

Request or provide clarification »

Demo


Using post_meta:
Using individual Nebula post meta functions with options:
  • Posted in PHP by
  • Modified on
  • Custom Format:
Other Nebula meta functions:
  • Function
  • No EXIF data found
Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Functions.php on line 706.

    No Hooks

    This function does not have any filters or actions available. Request one?
    PHP
            public function post_exif($icon=true){
                $the_icon = '';
                if ( $icon ){
                    $the_icon = '<i class="fa-solid fa-fw fa-camera-retro"></i> ';
                }
    
                $imgmeta = wp_get_attachment_metadata();
                if ( $imgmeta ){ //Check for Bad Data
                    if ( $imgmeta['image_meta']['focal_length'] === 0 || $imgmeta['image_meta']['aperture'] === 0 || $imgmeta['image_meta']['shutter_speed'] === 0 || $imgmeta['image_meta']['iso'] === 0 ){
                        $output = __('No valid EXIF data found', 'nebula');
                    } else { //Convert the shutter speed retrieve from database to fraction
                        if ( $imgmeta['image_meta']['shutter_speed'] > 0 && (1/$imgmeta['image_meta']['shutter_speed']) > 1 ){
                            if ( (number_format((1/$imgmeta['image_meta']['shutter_speed']), 1)) == 1.3 || number_format((1/$imgmeta['image_meta']['shutter_speed']), 1) == 1.5 || number_format((1/$imgmeta['image_meta']['shutter_speed']), 1) == 1.6 || number_format((1/$imgmeta['image_meta']['shutter_speed']), 1) == 2.5 ){
                                $pshutter = '1/' . number_format((1/$imgmeta['image_meta']['shutter_speed']), 1, '.', '') . ' ' . __('second', 'nebula');
                            } else {
                                $pshutter = '1/' . number_format((1/$imgmeta['image_meta']['shutter_speed']), 0, '.', '') . ' ' . __('second', 'nebula');
                            }
                        } else {
                            $pshutter = $imgmeta['image_meta']['shutter_speed'] . ' ' . __('seconds', 'nebula');
                        }
    
                        $output = '<time datetime="' . date('c', $imgmeta['image_meta']['created_timestamp']) . '"><span class="month">' . date('F', $imgmeta['image_meta']['created_timestamp']) . '</span> <span class="day">' . date('j', $imgmeta['image_meta']['created_timestamp']) . '</span><span class="suffix">' . date('S', $imgmeta['image_meta']['created_timestamp']) . '</span> <span class="year">' . date('Y', $imgmeta['image_meta']['created_timestamp']) . '</span></time>, ';
                        $output .= $imgmeta['image_meta']['camera'] . ', ';
                        $output .= $imgmeta['image_meta']['focal_length'] . 'mm, ';
                        $output .= '<span style="font-style: italic; font-family: "Trebuchet MS", "Candara", "Georgia", serif; text-transform: lowercase;">f</span>/' . $imgmeta['image_meta']['aperture'] . ', ';
                        $output .= $pshutter . ', ';
                        $output .= $imgmeta['image_meta']['iso'] . ' ISO';
                    }
                } else {
                    $output = __('No EXIF data found', 'nebula');
                }
    
                return '<span class="meta-item meta-exif">' . $the_icon . $output . '</span>';
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?