如何为WordPress编辑器添加pre自定义标签?WordPress输入带格式的代码时,每次都需要手动输入 pre 标签很不方便。如何能够像编辑器带的 b 标签一样,点一下就自动输入。

WordPress增加自定义标签办法:

修改主题的 functions.php 文件,路径为:/网站路径/wp-content/themes/主题文件夹/functions.php,然后将以下代码添加

//添加编辑器自定义按钮

add_action(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’admin_print_scripts\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’my_quicktags\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);

function my_quicktags() {

wp_enqueue_script(

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’my_quicktags\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,

get_stylesheet_directory_uri().\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’/js/my_quicktags.js\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,

array(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’quicktags\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’)

);

}

主题文件夹\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\js 文件夹下新建 my_quicktags.js

内容如下:

QTags.addButton( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’hr\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’hr\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n<hr />\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ); //快捷输入一个hr横线,点一下即可

QTags.addButton( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’h1\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’h1\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”<h1>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n</h1>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” ); //快捷输入h1标签

QTags.addButton( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’h2\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’h2\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”<h2>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n</h2>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” ); //快捷输入h2标签

QTags.addButton( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’h3\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’h3\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”<h3>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n</h3>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” ); //快捷输入h3标签

QTags.addButton( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’p\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’P标签\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”<p>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n</p>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” ); //快捷输入p标签

QTags.addButton( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’eg_nextpage\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’分页符\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”<!–nextpage–>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” ); //快捷输入下一页标签

QTags.addButton( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’pre\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’代码高亮\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'<pre class=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”prettyprint linenums\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n</pre>\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” ); //快捷输入p标签

//QTags.addButton( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’my_id\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’my button\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );

//这儿共有四对引号,分别是按钮的ID、显示名、点一下输入内容、再点一下关闭内容(此为空则一次输入全部内容),\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n表示换行。

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部