WordPress.org

Forums

TinyMCE Advanced
syntax highlighting (3 posts)

  1. mxmanuel
    Member
    Posted 10 months ago #

    I have set up some shortcodes in my functions.php to be used in the editor and would love to highlight them in the editor.
    Is that possible and if so: how?

    Here is what I set up in my functions.php:

    /* Open Div */
    add_shortcode('div', 'be_div_shortcode');
    function be_div_shortcode($atts) {
    	extract(shortcode_atts(array('class' => '', 'id' => '' ), $atts));
    	$return = '<div';
    	if (!empty($class)) $return .= ' class="'.$class.'"';
    	if (!empty($id)) $return .= ' id="'.$id.'"';
    	$return .= '>';
    	return $return;
    }
    
    /* Close Div */
    add_shortcode('end-div', 'be_end_div_shortcode');
    function be_end_div_shortcode($atts) {
    	return '</div>';
    }
     function shortcode_empty_paragraph_fix( $content ) {
    
            $array = array (
                '<p>[' => '[',
                ']</p>' => ']',
                ']<br />' => ']'
            );
    
            $content = strtr( $content, $array );
    
            return $content;
        }
    
        add_filter( 'the_content', 'shortcode_empty_paragraph_fix' );

    Thanx for any answer
    mxmanuel

    https://wordpress.org/plugins/tinymce-advanced/

  2. Andrew Ozz
    WordPress Dev
    Plugin Author

    Posted 10 months ago #

    Shortcodes in the editor are just plain text strings. There's no direct way to highlight them.

    Depending on how you want the users to interact with your shortcode in the editor, you can replace it with a "placeholder image" similarly to how the more and nextpage tags work.

  3. mxmanuel
    Member
    Posted 10 months ago #

    Thanks a lot for your response.

    mxmanuel

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.