Plugin / Image Shortcake
fusionengineering, goldenapplesInstallation
Installation
Customizing Output
The whole point of using shortcodes rather than HTML tags for images is that you can customize the markup of images in your theme. This plugin offers three primary hooks to modify the output:
img_shortcode_output_img_tag: Filters the output of the tag before wrapping it in link or captionimg_shortcode_output_after_linkify: Filters the output of the tag after wrapping in linkimg_shortcode_output_after_captionify: Filters the output of the tag after wrapping in link and attaching caption
You can, of course, disregard the markup generated by this plugin altogether and use a template part for images if you want. This example adds EXIF data below all images containing those fields, in all post content:
in the theme’s functions.php:
`
add_filter( 'img_shortcode_output_img_tag', 'load_image_template', 10, 2 );
function load_image_template( $_, $attributes ) {
ob_start();
get_template_part( 'inline-image' );
return ob_get_clean();
}
`
in a template file called inline-image.php:
`
<?php
$attachment = $attributes['attachment'];
$size = $attributes['size'];
$class = $attributes['classes'];
$align = $attributes['align']
$alt = $attributes['alt']
$linkto = $attributes['linkto']
$attachment_meta = wp_get_attachment_metadata( intval( $attachment ) );
$exif_data = ( $attachment_meta['image_meta']['camera'];
echo wp_get_attachment_image( $attachment, $size, null,
array(
'class' => "$class $align attachment-$size",
'alt' => $alt,
)
);
if ( is_array( $exif_data ) ) {
echo '<ul class="image-meta">';
foreach ( $exif_data as $field => $value ) {
echo '<li>' . $field . ': ' . $value . '</li>';
}
echo '</ul>';
}
`
Data Migration
The plugin comes with two WP-CLI commands to migrate images in your existing content into the [img] shortcode format used by
this plugin. Note: if it isn’t clear, this is an early release — use at your own risk, and make sure you’ve backed up your posts before migrating!
wp image-shortcake migrate <ids> [--dry-run]
This command searches the post content of the posts specified in <ids>, and replaces any <img> tags or [caption] shortcodes with [img]
shortcodes. Currently it only catches images added through the media library; custom img tags will not be converted.
If you add the --dry-run flag, no replacements will actually be performed, just a summary report of the changes which would have been made.
wp image-shortcake revert <ids> [--dry-run]
This command finds all [img] shortcodes in the content of any of the posts specified in <ids>, and replaces them with the markup that would be generated by those shortcodes. Note that this runs any filters in your theme, so that if you have filtered the output of the shortcodes at any output, those filters will be reflected in the coverted post content.
Ratings
Rating breakdown
Details Information
Version
First Released
Total Downloads
Wordpress Version
Tested up to:
Require PHP Version:
Tags
Contributors
Languages
The plugin hasn't been transalated in any language other than English.
DIRECTORY DISCLAIMER
The information provided in this THEME/PLUGIN DIRECTORY is made available for information purposes only, and intended to serve as a resource to enable visitors to select a relevant theme or plugin. wpSocket gives no warranty of any kind, express or implied with regard to the information, including without limitation any warranty that the particular theme or plugin that you select is qualified on your situation.
The information in the individual theme or plugin displayed in the Directory is provided by the owners and contributors themselves. wpSocket gives no warranty as to the accuracy of the information and will not be liable to you for any loss or damage suffered by you as a consequence of your reliance on the information.
Links to respective sites are offered to assist in accessing additional information. The links may be outdated or broken. Connect to outside sites at your own risk. The Theme/Plugin Directory does not endorse the content or accuracy of any listing or external website.
While information is made available, no guarantee is given that the details provided are correct, complete or up-to-date.
wpSocket is not related to the theme or plugin, and also not responsible and expressly disclaims all liability for, damages of any kind, arising out of the use, reference to, or reliance on, any information or business listed throughout our site.