Opened 3 years ago
Last modified 5 months ago
#14380 accepted defect (bug)
Caption shortcode inserts inline style forcing width of containing div
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Shortcodes | Version: | |
| Severity: | minor | Keywords: | 3.2-early dev-feedback has-patch |
| Cc: | iandunn, justin@… |
Description
This is related to #9066.
The problem is that the image caption shortcode inserts an inline style on the containing div which sets the width to an arbitrary value which cannot be overriden by the theme's stylesheet.
The proposed solution is to replace the shortcode function with a custom one which creates the markup without the inline style, but this is undesirable. It adds unnecessary complexity for beginners and is just generally annoying and shouldn't be necessary.
Creating an inline style violates web standards and contradicts the philosophy behind a theme-based architecture.
The inline style on the div should be removed so that theme developers can style the caption like they would any other element, without having to resort to inconvenient workarounds.
Attachments (2)
Change History (14)
comment:1
markjaquith
— 2 years ago
- Milestone changed from Awaiting Review to Future Release
comment:2
nacin
— 2 years ago
- Keywords needs-patch added; caption inline style removed
- Owner set to nacin
- Status changed from new to accepted
3.2 with a patch.
solarissmoke
— 2 years ago
comment:3
solarissmoke
— 2 years ago
- Keywords has-patch needs-testing added; needs-patch removed
First pass at a fix is attached.
Taking away the width property causes "alignnone" captions to fill the whole width of the container. I have fixed this by modifying the style in TwentyTen, but this may have unintended consequences, so needs to be tested.
I realised while doing this that SCRIPT_DEBUG does load .dev scripts for tinyMCE plugins - you have to switch them round manually, which is a bit messy. I might open another ticket to see if this can be changed.
comment:5
smerriman
— 2 years ago
The inline width is necessary. The point of using an inline width is to allow captions which are wider than the image itself to wrap. There is no way to accomplish this with CSS alone if you get rid of the inline style.
comment:6
solarissmoke
— 2 years ago
- Keywords dev-feedback added; has-patch needs-testing removed
Hmm. Maybe they we should add a filter to the html output so that theme/plugin authors can override the inline styles if they want to?
comment:7
wonderboymusic
— 5 months ago
- Keywords needs-refresh added
comment:8
iandunn
— 5 months ago
- Keywords needs-refresh removed
I tried to get it working with CSS alone awhile back and couldn't, so I agree with smerriman that the inline width is required. I added a patch that creates a new wp-caption-width filter that themes can use to modify the width instead.
comment:10
greenshady
— 5 months ago
- Cc justin@… added
comment:11
iandunn
— 5 months ago
It sounds like the main obstacle brought up in #17044 was breaking backwards compatibility. The latest patch here just adds a filter around the width, so it won't break anything by default. The filter still allows theme devs to change the width to exactly what they want (including the exact size of the image, without padding), without having to rebuild the entire shortcode output, so it's much more convenient.
comment:12
iandunn
— 5 months ago
- Keywords has-patch added
You're right. This is pretty lame.