如何在编辑器的文本选项卡中添加短代码?

时间:2014-03-14 04:47:24

标签: wordpress editor shortcode

查看下面的图片,了解我的意思。

tab text http://i60.tinypic.com/2uhbgw2.jpg

我知道如何将镜头代码添加到tinymce中,但我不知道如何将短代码添加到文本选项卡。我想在"全屏"旁边添加我的短代码。按钮。任何解决方案?

1 个答案:

答案 0 :(得分:0)

有趣的问题,无法在此处或WordPress Developers找到任何引用,并在Japanese page上找到解决方案。

在代码中,我们仅在页面/wp-admin/post-new.php/wp-admin/post.php上触发过滤器挂钩,并且仅针对page帖子类型。

<?php
/**
 * Plugin Name: (SO) Add buttons to Text mode editor
 * Plugin URI:  http://stackoverflow.com/a/22425171/1287812
 * Description: Based on http://fog-town.net/note/web/addquicktag-unplugged/
 * Author:      brasofilo
 * License:     GPLv3
 */

// Hook only in this admin pages
foreach( array( 'post', 'post-new' ) as $hook )
    add_action( "load-$hook.php", 'setup_so_22396339' );

// Hook only for the 'page'  post type
function setup_so_22396339()
{
    global $typenow;
    if( 'page' !== $typenow )
        return;
    add_filter( 'quicktags_settings', 'quicktags_so_22396339', 10, 2 );
    add_action( 'admin_print_footer_scripts', 'my_quicktags_so_22396339' );
}

// Default buttons (remove buttons from the comma-separated string)
function quicktags_so_22396339( $qtInit, $editor_id ) 
{
    // There's another editor for the Comments box (editor_id == 'replycontent')
    if( 'content' === $editor_id )
        $qtInit['buttons'] = 'link,block,img,ul,ol,li,code,more,spell,close,fullscreen';
    return $qtInit;
}

// Add new buttons
function my_quicktags_so_22396339() 
{ 
    // Don't know how to target only the main content editor. Changes are applied to both editors (content and comments).
    ?>
    <script type="text/javascript">
        //QTags.addButton('ID', 'label', 'start_tag', 'end_tag', 'access_key', 'title', 'priority', 'instance');
        QTags.addButton( 'shortcode_1', 'shortcode 1', '[shortcode1]', '[/shortcode1]', '', 'Tooltip about the shortcode 1', '1', '' );
        QTags.addButton( 'shortcode_2', 'shortcode 2', '[shortcode2 category="ADD-THE-CATEGORY-ID"]', '', '', 'Tooltip about the shortcode 2', '1', '' );
        QTags.addButton( 'pre_tag', 'my-pre', '<pre>', '</pre>', '', '<pre></pre>', '1', '' );
        QTags.addButton( 'div_tag', 'my-div', '<div>', '</div>', '', '<div></div>', '101', '' );
        QTags.addButton( 'span_tag', 'my-span', '<span>', '</span>', '', '<span></span>', '150', '' );
    </script>
    <?php
}

全屏之后无法放置自定义按钮,请检查QTags.addButton中的优先级:

enter image description here

相关问题