最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How to use get_theme_mod in gutenberg editor wordpress?

programmeradmin1浏览0评论

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>;
}

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>;
}
Share Improve this question asked Dec 17, 2020 at 19:04 Lars FliegerLars Flieger 1415 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论