我试图在我的WordPress古滕贝格中添加语言切换链接,这样我就可以轻松切换到相应的语言编辑页面。
我遵循这个步骤:https://developer.wordpress.org/block-editor/developers/slotfills/plugin-document-setting-panel/。
“语言开关”部分显示成功,但我不知道如何添加编辑链接。
我的想法是:
要获得编辑链接,我们需要知道编辑链接。
然而,我被第三步困住了,我不知道如何正确地得到帖子的名字.
下面是我的代码:
import { registerPlugin } from '@wordpress/plugins';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
const { select } = wp.data;
const title = select("core/editor").getEditedPostAttribute( 'title' );
const languageSwitcher = () => (
<PluginDocumentSettingPanel
name="custom-panel"
title="Language Switcher"
className="custom-panel"
>
<a>English {title}</a>
<a>简体中文</a>
<a>繁體中文</a>
</PluginDocumentSettingPanel>
);
registerPlugin( 'language-switcher', {
render: languageSwitcher,
icon: 'translation',
} );现在,选择(“核心/编辑器”).getEditedPostAttribute( 'title‘)返回undefined。
我真的很感激你的帮助!谢谢!
发布于 2021-03-09 22:06:33
您是否尝试将wp-数据添加到您的wp_enqueue_script中。例如:
wp_enqueue_script(
'your-doc',
plugins_url( 'build/yourDoc.js', __DIR__ ),
[ 'wp-i18n', 'wp-edit-post', 'wp-element', 'wp-data' ],
'0.0.1',
true
);https://stackoverflow.com/questions/65785978
复制相似问题