Is it possible to apply inline styles to all blocks via filters? Or do only some blocks support it? basically I want to add the ability of adding a background image to a single column. So I added an extra attribute to store the background img url (named backgroundImg) and tested that its saved.

I am trying to use blocks.getSaveContent.extraProps to apply the background image to the inline style like so..

if ("wp-block-column" === props.className) {
    return lodash.merge(props, {
        style: {
            backgroundImage: "url(" + props.backgroundImg + ")",

When I run this however the background IMG url is 'undefined'. However I have tested and know that props.backgroundImg is being saved. I can add more of my code as needed, but any ideas on why it isn't applying the saved url?

  • If it's coming up as 'undefined' it may that the method you're using to obtain the saved image isn't working as expected. So it's there in the DB and if you're seeing undefined then you are getting it into element... ...but it looks as though your attempt to get the saved image isn't working. – Tony Djukic Jul 24 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.