[WordPress教程]WordPress后台添加文章编辑器下拉式短代码功能
wordpress文章修正器添加短代码的功用有2种
一种是直接添加在修正器面板里面,这样要是添加的短代码功用过多了,就占用的空间许多,而且杂乱
为了便当修正,简略选择,能够选择下拉式的方式,便当编撰文章或者或者修正文章
当然选择哪种还是自己决定
以下是经过修改过,简洁很多,又方便
直接将代码丢到主题 functions.php 文件中即可:
/******后台编辑器添加下拉式按钮*******/
function QGG_select(){
echo '
<select id="short_code_select">
<option value="请选择一个短代码!!!">〓〓〓插入文章短代码〓〓〓</option>
<option value="<h2>标题【段落重点h2】</h2>">【1】文章标题【段落重点h2】</option>
<option value="<h3>标题【段落重点h3】</h3>">【2】文章标题【段落重点h3】</option>
<option value="<h4><span>标题【段落重点h4】</span></h4>">【3】文章标题【段落重点h4】</option>//添加新的功能直接按照<option value="请选择一个短代码!!!">插入短代码</option>添加下一列
</select>';
}
if (current_user_can('edit_posts') && current_user_can('edit_pages')) {
add_action('media_buttons', 'QGG_select', 11);
}
function QGG_button() {
echo '<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#short_code_select").change(function(){
send_to_editor(jQuery("#short_code_select :selected").val());
return false;
});
});
</script>';
}
add_action('admin_head', 'QGG_button');