wordpress 多文本编辑框 怎么实现

如果您希望在后台文章编辑框中使用 WYSIWYG 编辑器,可以考虑以下替代方案:

  1. 自定义文章类型:创建一个自定义文章类型,并在其编辑器中使用 WYSIWYG 编辑器。这样,您可以在后台创建具有样式的文章,并在前台使用自定义模板来显示它们。

  2. 自定义文章元框:创建一个自定义文章元框(Meta Box),在其中使用 WYSIWYG 编辑器。这样,您可以在文章编辑页面的侧边栏或底部添加一个具有 WYSIWYG 编辑器的自定义字段,以便在后台为每篇文章输入自定义内容。

方法一: 在functions.php中添加以下代码

add_action('add_meta_boxes', 'add_custom_meta_box');

function add_custom_meta_box() {
	add_meta_box('custom_text_meta_box', 'Custom Text', 'render_custom_text_meta_box', 'post', 'normal', 'high');
}

// 渲染自定义文章元框
function render_custom_text_meta_box($post) {
	$content = get_post_meta($post->ID, 'custom_text', true);
	$editor_id = 'custom_text_editor';

	wp_editor($content, $editor_id, array(
		'textarea_name' => 'custom_text',
		'textarea_rows' => 10,
		'wpautop' => true
	));
}

// 保存自定义文章元框的值
add_action('save_post', 'save_custom_text_meta_box');

function save_custom_text_meta_box($post_id) {
	if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
		return;
	}

	if (isset($_POST['custom_text'])) {
		$custom_text = wp_kses_post($_POST['custom_text']);
		update_post_meta($post_id, 'custom_text', $custom_text);
	}
}

方法二:安装Advanced Custom Fields插件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值