#14380 closed defect (bug) (fixed)
Caption shortcode inserts inline style forcing width of containing div
Reported by: | iandunn | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.7 | Priority: | normal |
Severity: | minor | Version: | |
Component: | Shortcodes | Keywords: | 3.2-early dev-feedback has-patch |
Focuses: | Cc: |
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 (3)
Change History (21)
#2
@
14 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.
#3
@
14 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.
#5
@
14 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.
#6
@
14 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?
#8
@
12 years 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.
#11
@
12 years 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.
#13
@
11 years ago
Any opinions 14380-filter.diff
? Seems like this is an easy close for 3.7 if nobody objects.
#14
@
11 years ago
If we are going to add a filter, ideally should it enable the ability to remove the inline style all together?
Style note, our filters generally use underscores rather than hyphens, and wp_
only when they are filtering a return value of a function and the filter is the same name as said wp_
function.
You're right. This is pretty lame.