Title: stop inline styling when using [caption] shortcode
Last modified: October 26, 2020

---

# stop inline styling when using [caption] shortcode

 *  [haddlyapis](https://wordpress.org/support/users/haddlyapis/)
 * (@haddlyapis)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/stop-inline-styling-when-using-caption-shortcode/)
 * HI there,
    I am currently running a header CSP check on my site for or XXS errors.
   On one page, I have used the WordPress shortcode `[caption]` many times to show
   many images. When using the caption shortcode, [https://codex.wordpress.org/Caption_Shortcode](https://codex.wordpress.org/Caption_Shortcode)
   you **must** enter a `width` value. But this value is then inserted as an inline
   style value: `[caption id="" align="aligncenter" width="300"].......[/caption]`
   results in `<figure style="width: 300px"` being output as inline styling. I would
   like to enter this width from a style sheet. Can anyone advise on this please?
    -  This topic was modified 5 years, 7 months ago by [haddlyapis](https://wordpress.org/support/users/haddlyapis/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fstop-inline-styling-when-using-caption-shortcode%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/stop-inline-styling-when-using-caption-shortcode/#post-13582423)
 * Look at the Code Reference for the shortcode: [https://developer.wordpress.org/reference/functions/img_caption_shortcode/](https://developer.wordpress.org/reference/functions/img_caption_shortcode/)
   
   and you can see that you can override the entire markup with the ‘img_caption_shortcode’
   filter, or you can affect the width with the ‘img_caption_shortcode_width’ filter.
   The comment on the width filter says “To remove this inline style, return zero.”
 *  Thread Starter [haddlyapis](https://wordpress.org/support/users/haddlyapis/)
 * (@haddlyapis)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/stop-inline-styling-when-using-caption-shortcode/#post-13586587)
 * Hi there,
    thank you for pointing me in this direction. I tried adding the following
   to my functions.php file, but this was not the solution: `apply_filters( 'img_caption_shortcode_width',
   $width = 0 , $atts, $content );` As I am not a plugin developer, I just need 
   to know where to return the 0. thx in advance.
 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/stop-inline-styling-when-using-caption-shortcode/#post-13587711)
 * OK, the way it works is that filter functions can exist at any time, and are 
   applied by the core function in a certain place. You add your filter function
   to the list to be applied.
    So instead of the code you show, it would be more
   like
 *     ```
       function my_img_caption_shortcode_width ($width, $atts, $content) {
         return 0;
       }
       add_filter( 'img_caption_shortcode_width', 'my_img_caption_shortcode_width', 10, 3 );
       ```
   
 * You could check the $atts or $content if you need to, but if you will always 
   return 0, then no need to.
 *  Thread Starter [haddlyapis](https://wordpress.org/support/users/haddlyapis/)
 * (@haddlyapis)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/stop-inline-styling-when-using-caption-shortcode/#post-13590159)
 * [@joyously](https://wordpress.org/support/users/joyously/). Thank you so much.
   This worked perfectly. All the best!!!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘stop inline styling when using [caption] shortcode’ is closed to new 
replies.

## Tags

 * [caption](https://wordpress.org/support/topic-tag/caption/)
 * [css](https://wordpress.org/support/topic-tag/css/)

 * In: [Everything else WordPress](https://wordpress.org/support/forum/miscellaneous/)
 * 4 replies
 * 2 participants
 * Last reply from: [haddlyapis](https://wordpress.org/support/users/haddlyapis/)
 * Last activity: [5 years, 7 months ago](https://wordpress.org/support/topic/stop-inline-styling-when-using-caption-shortcode/#post-13590159)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
