Title: Custom Classes for Shortcode
Last modified: August 22, 2016

---

# Custom Classes for Shortcode

 *  Resolved [Jürgen Hörmann](https://wordpress.org/support/users/hoermannj/)
 * (@hoermannj)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/custom-classes-for-shortcode/)
 * Hi.
 * I use your plugin on every Worpress Site I set up. It is absolutely great.
 * One feature I’m missing right now is the possibillity to add a custom class to
   the shortcode (and widget). Basically what I do is creating blocks for different
   layout positions that get different styling per position. Unfortunately some 
   themes do not assign css classes to parent elements to properly address the output
   of the Custom Post Widget.
    Additionally if your theme is based on a css grid
   framework like bootstrap you can assign grid-width classes to easily fit the 
   Custom Post Widgets into the page layout.
 * Maybe you can extend the shortcode like [content_block id=47 slug=my-block **
   class=col-md-8**] and/or add a field “css class” to the edit page.
 * Thanks for this great Plug-In
 * [https://wordpress.org/plugins/custom-post-widget/](https://wordpress.org/plugins/custom-post-widget/)

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

 *  [luissierra](https://wordpress.org/support/users/luissierra/)
 * (@luissierra)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/custom-classes-for-shortcode/#post-5800046)
 * … And if We Could Also select a background from the image gallery.
 * Then it would be perfect. 🙂
 * Thanks
 *  Plugin Author [Johan van der Wijk](https://wordpress.org/support/users/vanderwijk/)
 * (@vanderwijk)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/custom-classes-for-shortcode/#post-5800153)
 * Hi Jürgen, the functionality for adding a custom class to the shortcode is already
   there. It works exactly like in your example. I have updated the FAQ since this
   feature was not documented yet.
 * When using the widget the plugin automatically adds an ID to the surrounding 
   div like so: `id="custom_post_widget-17"`. Because it includes the post ID of
   the content block, it is always unique. Also, the class `widget_custom_post_widget`
   is added to the div.
 * [@luis](https://wordpress.org/support/users/luis/): You can use the classes and/
   or ID as mentioned above to add a background to the widget.
 *  Thread Starter [Jürgen Hörmann](https://wordpress.org/support/users/hoermannj/)
 * (@hoermannj)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/custom-classes-for-shortcode/#post-5800161)
 * Great!
 * Thank you very much Johan
 *  [StephanR](https://wordpress.org/support/users/stephanr-1/)
 * (@stephanr-1)
 * [11 years ago](https://wordpress.org/support/topic/custom-classes-for-shortcode/#post-5800238)
 * Hi Johan van der Wijk,
 * > “When using the widget the plugin automatically adds an ID…”
 * Unfortunately this seems to be “widget order” id and not the real post-id. What
   do you think?
 * Thank you.
 *  Plugin Author [Johan van der Wijk](https://wordpress.org/support/users/vanderwijk/)
 * (@vanderwijk)
 * [11 years ago](https://wordpress.org/support/topic/custom-classes-for-shortcode/#post-5800239)
 * Hi Stephan,
 * You are correct, when using the shortcode the post ID is added to the div but
   when using a widget this is the widget order. I had not noticed this difference
   before but it is not something I can change now (because this will affect existing
   websites). But since both ID’s are unique, this should not be a problem though.
 *  [StephanR](https://wordpress.org/support/users/stephanr-1/)
 * (@stephanr-1)
 * [11 years ago](https://wordpress.org/support/topic/custom-classes-for-shortcode/#post-5800241)
 * Hi Johan van der Wijk,
 * Yes I understand you can’t back for the div id. However you can add a class like“
   custom-post-great-plugin–widget-for-post-id-***”.
 * Thank you.
 *  Plugin Author [Johan van der Wijk](https://wordpress.org/support/users/vanderwijk/)
 * (@vanderwijk)
 * [11 years ago](https://wordpress.org/support/topic/custom-classes-for-shortcode/#post-5800242)
 * Yes, that would probably be possible but why would you need that if you already
   have a unique ID to apply your styling to?

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

The topic ‘Custom Classes for Shortcode’ is closed to new replies.

 * ![](https://ps.w.org/custom-post-widget/assets/icon.svg?rev=2884166)
 * [Content Blocks (Custom Post Widget)](https://wordpress.org/plugins/custom-post-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-post-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-post-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-post-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-post-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-post-widget/reviews/)

## Tags

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

 * 7 replies
 * 4 participants
 * Last reply from: [Johan van der Wijk](https://wordpress.org/support/users/vanderwijk/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/custom-classes-for-shortcode/#post-5800242)
 * Status: resolved