也想出现在这里?联系我们

实现wordpress自定义字段面板调用tinymce编辑器

2023.11.11 wordpress教程
  • 文章介绍
  • 升级版本
  • 评价&建议

要在WordPress自定义字段面板中调用TinyMCE编辑器,您可以使用以下步骤:

  1. 添加自定义字段: 首先,在您的主题或插件中创建一个自定义字段。您可以使用add_post_meta()函数来添加自定义字段。

    add_post_meta($post_id, 'custom_field_name', '', true);

    这将创建一个名为'custom_field_name'的自定义字段。

  2. 添加TinyMCE编辑器: 在您的自定义字段面板中,添加一个textarea元素,用于存储内容。确保为textarea元素添加唯一的ID。

    这将在自定义字段面板中显示一个textarea框。

  3. 初始化TinyMCE编辑器: 使用JavaScript初始化TinyMCE编辑器。您需要确保在WordPress加载TinyMCE之后执行以下代码。

    jQuery(document).ready(function($) {
       if (typeof tinymce !== 'undefined') {
           tinymce.init({
               selector: 'textarea#custom_field_editor',
               height: 300,
               theme: 'modern',
               plugins: 'wpautop',
               toolbar: 'bold italic | bullist numlist | link',
               wpautop: true,
           });
       }
    });

    这会将TinyMCE编辑器附加到名为'custom_field_editor'的textarea。

  4. 保存内容: 在您的主题或插件中,确保在保存帖子时将textarea中的内容保存到自定义字段中。

    update_post_meta($post_id, 'custom_field_name', $_POST['custom_field_name']);

    这将更新名为'custom_field_name'的自定义字段值。

通过这些步骤,您可以在WordPress自定义字段面板中成功调用TinyMCE编辑器。记得根据您的需求自定义编辑器的配置选项和工具栏按钮。

有用0
  • 2023.11.11初次和大家见面了!

等待您对该主题的建议

发表评论

还能输入240个字

Hi, 欢迎加入Wordpress技术交流群,带你装逼带你飞!

我要入群
也想出现在这里?联系我们
wordpress加速

我来推荐一个更牛逼的给你看看?

  • 猛戳我吧