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

3 Answers 3


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.

  • thanks great answer.we should always answer in WordPress way if their any.I'm a newbie and learning how to answer on stackoverflow or solve a problem in wordpress way.thanks again. Jun 7, 2013 at 12:37
  • @Ravs this is the best way for WordPress and everything overall. You shouldn't try and emulate a <code> tag by using a <span> tag. And shortcodes are not supposed to be used for plain HTML, that's what HTML is for
    – shea
    Jun 7, 2013 at 23:55

you can create a shortcode for this

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:



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
  • 2
    That is not Core functionality. In order for that work a plugin, which you do not name, must be installed. Note: both links you post refer to wordpress.com which is a hosted platform that includes some functionality not bundled with the Core and which I have to assume is why that shortcode works on those sites. This is not a viable answer as written.
    – s_ha_dum
    May 12, 2014 at 2:16
  • You're right in one point, the links refer to hosted platform, but after many posts readed, these short tags work also on non hosted wordpress sites without plugins... but I will check myself to be sure, thanks for answer @s_ha_dum May 12, 2014 at 10:29
  • I have never known a sourcecode shortcode to be bundled with WordPress. You are mistaken.
    – s_ha_dum
    May 12, 2014 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.