Tag <code> recognize language (Wordpress)?

Asked

Viewed 177 times

1

I do not understand much of this tag, but wanted to know how to make a scheme of the style of this site in a Wordpress blog, code example:

string demo = "StackOverflow";
if(demo.Lenght == 13)
{
    demo += "Brasil";
}

How to make it recognize reversed words and change colors?

  • This in wordpress post? or via code same?

  • Either one of the two, being html, because it is to be published in Wordpress and it only reads html.. It has the code tag, but it only separates a block for the code, does not identify the reverse words of each language

2 answers

2

Inside a website, you will need some library to be able to "underline" or style your code. In this aspect, there is the https://highlightjs.org/, which is a javascript library that can color your source code.

In a simple example, after including the library on your page, you could use it for javascript:

<pre>
 <code class="javascript">
  string demo = "StackOverflow";
  if(demo.Lenght == 13)
  {
      demo += "Brasil";
  }
 </code>
</pre>
  • This my answer fits in the general sense -- has several plugins and shortcodes in Wordpress that can do the same.

  • @Pablopalaces thanks for the help in English! D

2


If you just add the Highlight in the post you can escape the code with [sourcecode language='nome da linguaguem']:

[sourcecode language='javascript']
  string demo = "StackOverflow";
  if(demo.Lenght == 13){
    demo += "Brasil";
  }
[/sourcecode]

Is rendered as:

inserir a descrição da imagem aqui

The list of available languages and other settings are available on manual

  • Being this one shortcode in Wordpress, correct?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.