1

In my old WordPress themes (before Gutenberg) I used get_theme_mod to get custom values for certain things in the theme.

get_theme_mod( 'news_custom_headline' );

Now I would like to use the gutenberg editor, however still want to access data from the customizer. How can I do something like this:

save({ attributes }) {
   return <p>Value from backend: get_theme_mod( 'news_custom_headline' ) </p>;
}
1

You don't, if you need a dynamic value you have to have a server rendered block.

Otherwise, if you managed to get the theme mod, it would be frozen to the value it had at save, and changing the value in the customiser would not update the blocks. So use a dynamic server rendered block and grab the value in PHP the same way you normally would.

2
  • Ah okay. True because if you save a page (created with a gutenberg block) it will save pure html in the database, correct? Alright, thank you! I'm going to take a look to these server rendered blocks. :) Thank you! Dec 17 '20 at 20:00
  • 1
    I managed to get it working! Thank you! Your answer was exactly what I'm looking for! Dec 17 '20 at 20:20

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.