WordPress 3.5.1添加后台编辑器按钮

作者:matrix 被围观: 3,203 次 发布时间:2013-04-24 分类:Wordpress 兼容并蓄 | 无评论 »

这是一个创建于 4020 天前的主题,其中的信息可能已经有所发展或是发生改变。

WordPress后台HTML编辑器中加入自定义按钮的方法之一。

不用折腾/wp-includes/js/quicktags.js文件。适用WordPress 3.5.1的版本。

步骤:

  1. 在主题目录内创建my-quicktags.js文件,写入:
QTags.addButton( '<', '<', '&lt;', '' ); //快捷输入<的html代码
QTags.addButton( '>', '>', '&gt;', '' );
QTags.addButton( 'hr', 'hr', "\n<hr />\n", '' );  //快捷输入一个hr横线,点一下即可
QTags.addButton( 'nextpage', 'nextpage', "\n<!--nextpage-->\n", '' ); //添加文章分页按钮
QTags.addButton( 'h1', 'h1', "\n<h1>", "</h1>\n" );  //快捷输入h1标签
QTags.addButton( 'h2', 'h2', "\n<h2>", "</h2>\n" );
QTags.addButton( 'h3', 'h3', "\n<h3>", "</h3>\n" );
//QTags.addButton( 'my_id', 'my button', '\n</span>', '</span>\n' );
//这儿共有四对引号,分别是按钮的ID、显示名、点一下输入内容、再点一下关闭内容(此为空则一次输入全部内容),\n表示换行
  1. 在主题目录内的functions.php中添加如下代码:

<?php
//自定义HTML编辑器按钮
add_action('admin_print_scripts', 'my_quicktags');
function my_quicktags() {
wp_enqueue_script(
'my_quicktags',
get_stylesheet_directory_uri().'/my-quicktags.js',
array('quicktags')
);
}
?>

效果图:

添加后台编辑器按钮

来自:Mr.ZIYI | 私人后花园

ps:有些主题functions.php中添加代码后会出现error,甚至后台都不能访问(把最近使用过的主题文件夹换为其他名字即可解决)

修改代码要慎重!

 

其他文章:
本文固定链接:https://www.hhtjim.com/wordpress-3-5-1-track-of-editor-button-to-add-the-background.html
matrix
本文章由 matrix 于2013年04月24日发布在Wordpress, 兼容并蓄分类下,目前没有通告,你可以至底部留下评论。
转载请注明:WordPress 3.5.1添加后台编辑器按钮-HHTjim'S 部落格
关键字:

添加新评论 »

 🙈 😱 😂 😛 😭 😳 😀 😆 👿 😉 😯 😮 😕 😎 😐 😥 😡 😈 💡

插入图片

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!