How can I highlight syntax like it appears on stackoverflow?

Suppose I am writing a post and want to highlight only a couple of characters: like this. How can I achieve this?

Related posts

3 comments

  1. you can create a shortcode for this

    <?php
    add_shortcode('highlight','ravs_hightlight');
    function ravs_hightlight( $atts, $content=""){
      return '<span class="highlight">'.$content.'</span>';
    }
    ?>
    

    paste above code in functions.php.

    use shortcode in wordpress editer like

    [highlight]test for hightlight short code[/highlight]
    

    your html output like

    <span class="highlight">test for hightlight short code</span>
    

    give some css to .highlight class

    Important Link:

    add_shortcode()

  2. This subject has been successfully discussed here, and here.

    Bungeshea is right, but you can also and simply add these tags in your text editor (not visual editor):

    [sourcecode language='CorrespondingLanguage']
        //Your code goes here
    [/sourcecode]
    

Comments are closed.