Home › Forums › General Issues › Block.json default attributes
When setting the default attributes in block.json, how can we set a default link color, default padding, etc?
I managed to set default align, alignText, backgroundColor and textColor… but the same format doesn’t work for links:
{
"name": "test-block",
"title": "Test Block",
"style": "file:./test-block.css",
"category": "custom",
"icon": "carrot",
"apiVersion": 2,
"acf": {
"mode": "preview",
"renderTemplate": "test-block.php",
"postTypes": [ "post" ]
},
"supports": {
"align": true,
"anchor": true,
"alignContent": false,
"color": {
"text": true,
"background": true,
"link": true,
"gradients": true
},
"alignText": true,
"spacing": {
"margin": [
"top",
"bottom"
],
"padding": true
},
"typography": {
"fontSize": true
}
},
"attributes": {
"backgroundColor": {
"type": "string",
"default": "black"
},
"textColor": {
"type": "string",
"default": "white"
},
"linkColor": {
"type": "string",
"default": "yellow"
},
"align": {
"type": "string",
"default": "wide"
},
"alignText": {
"type": "string",
"default": "center"
}
}
}
I tried adding this to the attributes but it doesn’t work for padding:
"spacing": {
"padding": {
"top": "3rem"
}
}
And I also tried adding the link colour to attributes like this, which also didn’t work:
"style": {
"elements": {
"link": {
"color": {
"type": "string",
"color": "yellow"
}
}
}
}
It sounds like you might have some CSS overriding the textColor. I don’t see anywhere in the Gutenberg docs that there should be a linkColor – blocks.json it meant to align ACF with WP standards. So links will follow textColor or what you’ve defined in the CSS.
Any reason why you don’t just make a CSS definition of the link color in that block?
All good.
A default link colour can be defined in block.json under attributes like this:
"style": {
"type": "object",
"default": {
"elements": {
"link": {
"color": {
"text": "var:preset|color|blue"
}
}
}
}
},
Seems to follow a different format to textColor and backgroundColor.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.