Title: Data Attributes JSON Object
Last modified: October 17, 2022

---

# Data Attributes JSON Object

 *  Resolved [Nick Heurter](https://wordpress.org/support/users/nickelanddimenl/)
 * (@nickelanddimenl)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/)
 * Hi mate!
 * First of all I would like to thank you for this awesome plugin, really cool!
 * But I have 1 question. I’m trying to use your plugin to set the settings for 
   the Slick Slider trough the data-attribute ‘data-slick’. (Here you can see how
   this works: [https://kenwheeler.github.io/slick/](https://kenwheeler.github.io/slick/)).
 * So I’m adding the following data-attribute to my Post Template core/block: ‘data-
   slick’. And I insert the following code inside the input field: {“slidesToShow”:
   4, “slidesToScroll”: 4}.
 * On frontend this results in: `data-slick="{&quot;slidesToShow&quot;: 4, &quot;
   slidesToScroll&quot;: 4}"`
 * I tried all different kind of settings, but I can’t get it working.
 * Could you please help?
 * Thanks already!
 * Kind Regards, Nick
    -  This topic was modified 3 years, 10 months ago by [Nick Heurter](https://wordpress.org/support/users/nickelanddimenl/).

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

 *  [websevendev](https://wordpress.org/support/users/websevendev/)
 * (@websevendev)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16105777)
 * Do single quotes work?
 * `{'slidesToShow': 4, 'slidesToScroll': 4}`
 * Do no quotes work?
 * `{slidesToShow: 4, slidesToScroll: 4}`
 * You can’t use normal quotes as they are already encasing the whole attribute 
   value.
    If `data-slick="{"slidesToShow": 4, "slidesToScroll": 4}"` worked the
   value of `data-slick` would be `{`.
 *  Thread Starter [Nick Heurter](https://wordpress.org/support/users/nickelanddimenl/)
 * (@nickelanddimenl)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16106422)
 * [@websevendev](https://wordpress.org/support/users/websevendev/) what a quick
   response, awesome! You’re faster than lightning!
 * But to answer your question: unfortunately not. I’ve tried it, but it doesn’t
   work. I have [created a codepen](https://codepen.io/nickheurter/pen/BaxEJdb) 
   to show you the non-working and working example.
 * As you can see I need to use the following format: `data-slick='{"slidesToShow":
   4, "slidesToScroll": 4}'`.
 * Is this possible with your plugin?
 *  [websevendev](https://wordpress.org/support/users/websevendev/)
 * (@websevendev)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16106539)
 * Yeah looks like it’s not possible then, as the attribute values will definitely
   be wrapped in `"` as opposed to `'`.
 * Here’s a hack you can use maybe:
 * Prepend `eval:` and use no quotes/single quotes like this: `eval:{slidesToShow:
   4, slidesToScroll: 4}` producing `data-slick="eval:{slidesToShow: 4, slidesToScroll:
   4}"`.
    Then add additional JS before initializing the slider:
 *     ```
       $('.slider[data-slick*="eval:"]').each(function() {
         eval('var data = ' + $(this).data('slick').replace('eval:', ''));
         $(this).data('slick', data);
       });
       $('.slider').slick();
       ```
   
 * This will evaluate the `{slidesToShow: 4, slidesToScroll: 4}` as it’s a valid
   JS object and assign it as the `data-slick` value. Alternatively you can use 
   a similar method to “fix” the `{&quot;slidesToShow&quot;: 4, &quot;slidesToScroll&
   quot;: 4}` HTML entities with JS as well probably.
 *  Thread Starter [Nick Heurter](https://wordpress.org/support/users/nickelanddimenl/)
 * (@nickelanddimenl)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16108034)
 * Thanks a lot mate! This works great!!
 * One thing that doesn’t work yet is the following code: `eval:{slidesToShow: 4,
   slidesToScroll: 4, centerMode: true, centerPadding: '60px' }`. Because in this
   situation there are stil quotes around the 60px. But when I try to add the following
   without the quotations around the 60px, it is also not working: `eval:{slidesToShow:
   4, slidesToScroll: 4, centerMode: true, centerPadding: 60px }`.
 * Do you also have a last suggestion how I could work around this? 😃 🥳
 *  [websevendev](https://wordpress.org/support/users/websevendev/)
 * (@websevendev)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16109364)
 * For me this seems to happen only for dynamic blocks (aka blocks that are rendered
   server side by PHP not directly with JS). For `core/paragraph` block `eval:{centerPadding:'
   60px'}` works, but adding the same attribute to `core/latest-comments` for example
   the quotes are escaped by the `esc_attr()` function.
 * Try adding this line to your child theme’s **functions.php**:
 * `remove_filter('afb_sanitize_attribute_value', 'esc_attr');`
 * Then the value should remain unescaped for dynamic blocks as well.
    Removing 
   it is technically less secure, but the only risks I can think of are **authenticated
   users** of your site who can **edit posts** in the first place but have malicious
   intent. If you’re the only user of your site then it shouldn’t really matter.
    -  This reply was modified 3 years, 10 months ago by [websevendev](https://wordpress.org/support/users/websevendev/).
    -  This reply was modified 3 years, 10 months ago by [websevendev](https://wordpress.org/support/users/websevendev/).
 *  Thread Starter [Nick Heurter](https://wordpress.org/support/users/nickelanddimenl/)
 * (@nickelanddimenl)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16117554)
 * Not all hero’s wear capes (or maybe you do)! But this is truly fantastic mate,
   it works!! Thanks a lot!! ❤️ 🤩
 *  Thread Starter [Nick Heurter](https://wordpress.org/support/users/nickelanddimenl/)
 * (@nickelanddimenl)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16117626)
 * One last question. This site has multiple users (so I’m not the only one using
   the site). What are the possible treats then with this filter:
 * `remove_filter('afb_sanitize_attribute_value', 'esc_attr');`
 *  [websevendev](https://wordpress.org/support/users/websevendev/)
 * (@websevendev)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16118098)
 * Honestly, I don’t think it opens up more possibilities than users with `editor`
   permissions already have. Worst case scenario they add some JavaScript that, 
   when you visit the page, will send them your login cookie, granting them admin
   access.
    They could add a well-crafted attribute that does it using this plugin,
   but they can just as well add the Custom HTML block to do that. So removing the
   filter only opens attack vectors when you have previously closed the earlier 
   ones, which I doubt is the case.
 * Anyone that has `unfiltered_html` permissions needs to be trusted basically. 
   It’s like giving someone keys to your house.
 *  Thread Starter [Nick Heurter](https://wordpress.org/support/users/nickelanddimenl/)
 * (@nickelanddimenl)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16119785)
 * Thanks for the explanation! 😃 And thanks again for your awesome support! I’ll
   give the plugin 5 stars, for the support and for the working of the plugin. It’s
   a really cool plugin!
 *  Thread Starter [Nick Heurter](https://wordpress.org/support/users/nickelanddimenl/)
 * (@nickelanddimenl)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16119787)
 * The issue is resolved.

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

The topic ‘Data Attributes JSON Object’ is closed to new replies.

 * ![](https://ps.w.org/attributes-for-blocks/assets/icon-256x256.png?rev=2588242)
 * [Attributes for Blocks](https://wordpress.org/plugins/attributes-for-blocks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/attributes-for-blocks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/attributes-for-blocks/)
 * [Active Topics](https://wordpress.org/support/plugin/attributes-for-blocks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/attributes-for-blocks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/attributes-for-blocks/reviews/)

 * 10 replies
 * 2 participants
 * Last reply from: [Nick Heurter](https://wordpress.org/support/users/nickelanddimenl/)
 * Last activity: [3 years, 10 months ago](https://wordpress.org/support/topic/data-attributes-json-object/#post-16119787)
 * Status: resolved