新增] code"键字preSS了tinyMCE [英] Add "code" button to wordpress tinyMCE

查看:190
本文介绍了新增] code"键字preSS了tinyMCE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注这个教程,和许多喜欢它:的http:// codex.word press.org / TinyMCE_Custom_Buttons

I've been following this tutorial, and many like it: http://codex.wordpress.org/TinyMCE_Custom_Buttons

function myplugin_addbuttons() {
   // Don't bother doing this stuff if the current user lacks permissions
   if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
     return;

   // Add only in Rich Editor mode
   if ( get_user_option('rich_editing') == 'true') {
     add_filter('mce_buttons', 'register_myplugin_button');
   }
}

//Should add 'code' to the tinyMce buttons on the rich editor.
function register_myplugin_button($buttons) {
   array_push($buttons, "code");
   return $buttons;
}


// init process for button control
add_action('init', 'myplugin_addbuttons');

所有我想要做的就是添加code按钮,富文本编辑器。它已经在HTML编辑器的一面。本教程中提到的方式,就好像我可以array_pushcode到按钮只写。但是,这是行不通的。我在做什么错了?

All I want to do is add the "code" button to the rich text editor. It's already in the HTML editor side. From the way the tutorial mentions it, it seems as though I could just write in array_push "code" into buttons. But it doesn't work. What am I doing wrong?

推荐答案

如果你有机会添加设置TinyMCE的配置(这我不知道您根据您的previous意见做),那么你可以添加以下

If you have access to add settings to the TinyMCE config (which I'm not sure you do based on your previous comments) then you could add the following.

style_formats:[{标题:code',内联:code'}]

这是什么需要做的是增加一个 code 的在样式下拉该项目将包装在code标记选定的文本。

What this will do is add a "code" item in the Style drop down that will wrap the selected text in the code tags.

如果你不能得到的配置添加这个,那么你可能需要制定一个TinyMCE的插件,编程注册该格式。 BTW,链接如何开发你引用的话语preSS文章TinyMCE的插件不再是正确的。查看如何对文章来代替。

If you can't get to the config to add this, then you may need to develop a TinyMCE plugin that registers that format programmatically. BTW, the link to how to develop a TinyMCE plugin on the WordPress article you reference is no longer right. Check out the How-to article instead.

最后,如果一切都失败了,你可以开发一个包装选定的文本(的 ed.selection.getContent())在code和返回它使用的 ed.selection.setContent()

Finally, if all else fails, you could develop a plugin that wraps the selected text (ed.selection.getContent()) in the code and returns it using ed.selection.setContent()

这篇关于新增] code"键字preSS了tinyMCE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆