Support

Account

Home Forums Backend Issues (wp-admin) WYSIWYG shortcode button not visible within flexible content Reply To: WYSIWYG shortcode button not visible within flexible content

  • Hi John,

    Thanks for your reply! I figured out that there was something wrong with initializing the shortcodes button. Everything is working fine now and this is the optimized code:

    add_action( 'after_setup_theme', 'shortcodes_button_setup' );
    
    if ( ! function_exists( 'shortcodes_button_setup' ) ) {
        function shortcodes_button_setup() {
            add_action( 'init', 'shortcodes_button' );
        }
    }
    
    if ( ! function_exists( 'shortcodes_button' ) ) {
        function shortcodes_button() {
            if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
                return;
            }
    
            if ( get_user_option( 'rich_editing' ) !== 'true' ) {
                return;
            }
    
            add_filter( 'mce_external_plugins', 'add_shortcodes_button' );
            add_filter( 'mce_buttons', 'register_shortcodes_button' );
        }
    }
    
    if ( ! function_exists( 'add_shortcodes_button' ) ) {
        function add_shortcodes_button( $plugin_array ) {
            $plugin_array['shortcodes_button'] = get_template_directory_uri().'/includes/shortcodes/js/shortcodes.js';
            return $plugin_array;
        }
    }
    
    if ( ! function_exists( 'register_shortcodes_button' ) ) {
        function register_shortcodes_button( $buttons ) {
            array_push( $buttons, 'shortcodes_button' );
            return $buttons;
        }
    }