• Resolved nht2007

    (@nht2007)


    Hello,
    Please tell me know how to add custom shortcode button to MCE, I try to hook ‘init’ but it’s not working.
    Please help

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Ben Carlo

    (@hinampaksh)

    Hey @nht2007,

    Thanks for posting! And apologies for the delayed response. Do you mind sharing the code you’re using so we can check? ??

    Ben

    Thread Starter nht2007

    (@nht2007)

    Hey @ben Carlo

    My shortcode:

    // Lazy Shortcode
    function lazyimage_shortcode( $atts ) {
    
        // Attributes
        $atts = shortcode_atts(
            array(
                'tieude' => '',
                'url'    => ''
            ),
            $atts,
            'lazyimage'
        );
    
        return '<img class="lazy loading" data-src="'.esc_html__($atts['url']).'" alt="'.esc_html__($atts['tieude']).'" title="'.esc_html__($atts['tieude']).'">';
    
    }
    add_shortcode( 'lazyimage', 'lazyimage_shortcode' );
    
    // Add TinyMCE button and plugin filters
    function lazyimage_tinymce_button() {
        if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
            add_filter( 'mce_buttons', 'lazyimage_register_tinymce_button' );
            add_filter( 'mce_external_plugins', 'lazyimage_tinymce_button_script' );
        }
    }
    add_action( 'init', 'lazyimage_tinymce_button' );
    • This reply was modified 7 years, 11 months ago by nht2007.
    Plugin Contributor Ben Carlo

    (@hinampaksh)

    Hey @nht2007,

    Can you try adding your filters at a high priority and see if it works? ??

    // Lazy Shortcode
    function lazyimage_shortcode( $atts ) {
    
        // Attributes
        $atts = shortcode_atts(
            array(
                'tieude' => '',
                'url'    => ''
            ),
            $atts,
            'lazyimage'
        );
    
        return '<img class="lazy loading" data-src="'.esc_html__($atts['url']).'" alt="'.esc_html__($atts['tieude']).'" title="'.esc_html__($atts['tieude']).'">';
    
    }
    add_shortcode( 'lazyimage', 'lazyimage_shortcode' );
    
    // Add TinyMCE button and plugin filters
    function lazyimage_tinymce_button() {
        if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
            add_filter( 'mce_buttons', 'lazyimage_register_tinymce_button', 99999 );
            add_filter( 'mce_external_plugins', 'lazyimage_tinymce_button_script', 99999 );
        }
    }
    add_action( 'init', 'lazyimage_tinymce_button' );

    Ben

    • This reply was modified 7 years, 11 months ago by Ben Carlo.
    Thread Starter nht2007

    (@nht2007)

    @hinampaksh wow, It’s worked.
    Awesome, thank you so so much

    Plugin Contributor Ben Carlo

    (@hinampaksh)

    No worries at all! Glad we could help. ??

    Enjoy BB!

    Ben

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘TinyMCE button’ is closed to new replies.