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?

Topic syntax-highlighting posts Wordpress

Category Web


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]

HTML language includes a special tag for displaying inline code. To apply it to your text, switch to the 'Text' visual editor tab and place the <code> tag before your bit of code, and the </code> tag afterwards.

If you want to use the backtick ` character for highlighting code like you do on Stack Overflow, check out this plugin by Tom McFarlin.


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()

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.