Last active
February 21, 2019 09:43
-
-
Save paul-frost/2ea5c8ce57aec116ed75 to your computer and use it in GitHub Desktop.
Responsive images in ExpressionEngine WYGWAM field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This method requires the CE Image addon. | |
Tell your editors to change the width/height/alignment in the image properties pop up to 300px or whatever and set the alignment if they want, but the actual size displayed on the page will be decided by you in the template code and CSS. | |
In the EE template: | |
{exp:ce_img:bulk max="500" crop="no" allow_scale_larger="no" quality="80" output='<a href="{orig}" class="embeded_image" title="{attr:title}" alt="{attr:alt}" style="{attr:style}"><img src="{made}" /></a>'} | |
{wygwam_field} | |
{/exp:ce_img:bulk} | |
In the CSS: | |
.embeded_image { | |
float: none; | |
margin-left: 0; } | |
@media only screen and (min-width: 550px) { | |
.embeded_image { | |
max-width: 50%; | |
margin: 0 2%; } | |
} | |
Or, if you want to have a caption included, get the editors to fill in the Altenrnative Text box with a caption (probably easier than getting them to use the Advanced tab and completing the Advisory Title, you could also edit the ckeditor language file to change the wording to Caption Text) and then wrap it all in a Div. Note that you need to move the Style attribute into the Div if you want the editors to be able to control the left/right alignment. They can also choose the width/height they want per instance up to the max size you set in the bulk tag: | |
{exp:ce_img:bulk max="500" crop="no" allow_scale_larger="no" quality="80" output='<div class="embeded_image" style="{attr:style}"><a href="{orig}" title="{attr:title}" alt="{attr:alt}"><img src="{made}" /></a><div class="caption">Caption: {attr:alt}</div></div>'} | |
and add this (or whatever stye you want) to your CSS: | |
.caption { | |
text-align: center; | |
font-weight: bold; | |
} | |
Apologies Steve I didn't get a notification of your comment.
No, my opening and closing paragraph tags are all in the right places. What version of EE, WYGWAM and CE Image are you using, I'm on 2.9.2, 3.3.3 and 2.4.5
I did notice that I should probably have used a div for the caption, so have edited the Gist.
weird, I usually get these notifications too.
Issue was the client placing the image inside of a p tag. Move the image outside and it's golden.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Paul, have you ever noticed with this approach that, for example, when you set
output='<div><img src="{made}"></div>'
Your generated markup becomes
whereas, without the output tag, every paragraph is as it should be?