• I want to add an image save data under the featured image on the single.php page. Save data needs to include:

    Upload : (exmpl: Mar 30, 2024 at 11:36)
    Uploaded by: (User name)
    File URL: (image url)
    Filetype: (PNG)
    File size: 15 KB
    Dimensions: 512 x 512

    I want to show this save data below the image. For this, I need to add some code to the single.php page. What is the code ? please help me…

Viewing 1 replies (of 1 total)
  • You can try to use this code.

    <?php
    // Get the featured image URL, dimensions, and file size
    $featured_image_id = get_post_thumbnail_id();
    $featured_image_url = wp_get_attachment_url($featured_image_id);
    $featured_image_meta = wp_get_attachment_metadata($featured_image_id);
    $featured_image_filetype = pathinfo($featured_image_url, PATHINFO_EXTENSION);
    $featured_image_filesize = size_format(filesize(get_attached_file($featured_image_id)), 2);
    
    // Get the upload date and uploader's username
    $featured_image_upload_date = get_the_date('M j, Y \a\t g:i', $featured_image_id);
    $featured_image_uploader_id = get_post_field('post_author', $featured_image_id);
    $featured_image_uploader_name = get_the_author_meta('display_name', $featured_image_uploader_id);
    
    // Display the featured image
    echo '<div>';
    the_post_thumbnail('large');
    echo '</div>';
    
    // Display the image save data
    echo '<div>';
    echo '<p><strong>Upload:</strong> ' . $featured_image_upload_date . '</p>';
    echo '<p><strong>Uploaded by:</strong> ' . $featured_image_uploader_name . '</p>';
    echo '<p><strong>File URL:</strong> <a href="' . $featured_image_url . '">' . $featured_image_url . '</a></p>';
    echo '<p><strong>Filetype:</strong> ' . $featured_image_filetype . '</p>';
    echo '<p><strong>File size:</strong> ' . $featured_image_filesize . '</p>';
    echo '<p><strong>Dimensions:</strong> ' . $featured_image_meta['width'] . ' x ' . $featured_image_meta['height'] . '</p>';
    echo '</div>';
    ?>
    
Viewing 1 replies (of 1 total)
  • The topic ‘I want to add an image save data under the featured image on the single.php page’ is closed to new replies.