今天想在自己博客“说说”模块上发布一个视频,因为视频很长,想使用哔哩哔哩视频嵌入,但是说说内容输入框只支持文本输入,没办法嵌入iframe
和第三方视频,所以才有了本次教程。下面是教程内容:
1.将后台说说模块的文本输入框修改为富文本输入框
打开主题文件,找到并打开inc/acf/acf-config.php,大概在2463行找到以下代码:
将'type' => 'textarea'
修改为'type' => 'wysiwyg'
acf_add_local_field_group(
array(
'key' => 'group_63382938e3b3e',
'title' => __('Content', 'zaxu'),
'fields' => array(
// Text
array(
'key' => 'field_6338294f47684',
'label' => __('Text', 'zaxu'),
'name' => 'zaxu_say_text',
'type' => 'wysiwyg', // 将textarea修改为wysiwyg富文本输入框
'instructions' => $text_instructions,
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => __('Say Something...', 'zaxu'),
'maxlength' => $text_length,
'rows' => 10,
'new_lines' => 'p',
),
2.修改前端,支持显示富文本格式的内容
找到并打开inc/functions/helpers.php,大概在4454行找到以下代码:
$author_id = get_post_field('post_author', $post_id);
$feed_full_text = esc_textarea( zaxu_get_field('zaxu_say_text', $post_id) );
$preprocess_text = nl2br(
str_replace(
' ',
' ',
$feed_full_text
)
);
//将上面的代码修改为:
$author_id = get_post_field('post_author', $post_id);
$feed_full_text = apply_filters( 'the_content', zaxu_get_field('zaxu_say_text', $post_id) ); //修改了这里
$preprocess_text = str_replace(
'',
'',
$feed_full_text
);
大概在4738行找到以下代码:
<div class="zaxu-say-feed-text-box">
<p class="zaxu-say-feed-text">' . $preprocess_text . '</p>
</div>
//将以上代码修改为:
<div class="zaxu-say-feed-text-box">
' . $preprocess_text . '
</div>
至此说说就可以支持富文本内容了