4

I am trying to add some c++ code in WordPress post, but some character become &lt/&amp/&gt.

How can I solve this problem?

I tried the following:

[sourcecode language="cpp" title="Code:"]
void build_LCP_array(void)
{
    LCP[0] = 0;
    int n = text.size(), i, j, id1, id2;
    for(i = 1; i < n; i++)
    {
        id1 = arr[i - 1].indx;
        id2 = arr[i].indx;
        LCP[i] = 0;
        for(j = step - 1; j >= 0; j--)
            if(Rank[j][id1] == Rank[j][id2] && Rank[j][id2])
            {
                LCP[i] += (1 << j);
                id1 += (1 << j);
                id2 += (1 << j);
            }
    }
}
[/sourcecode]

And Result:

void build_LCP_array(void)
{
    LCP[0] = 0;
    int n = text.size(), i, j, id1, id2;
    for(i = 1; i &lt; n; i++)
    {
        id1 = arr[i - 1].indx;
        id2 = arr[i].indx;
        LCP[i] = 0;
        for(j = step - 1; j &gt;= 0; j--)
            if(Rank[j][id1] == Rank[j][id2] &amp;&amp; Rank[j][id2])
            {
                LCP[i] += (1 &lt;&lt; j);
                id1 += (1 &lt;&lt; j);
                id2 += (1 &lt;&lt; j);
            }
    }
}
1
  • are you wanting just to show the code (<pre><code>) etc or to have syntax highlighting?
    – atmd
    Commented Jan 14, 2015 at 15:09

2 Answers 2

2

According to here: http://en.support.wordpress.com/code/posting-source-code/ , you should use

[code language="cpp"] your code here [/code]

Try this plugin too: https://wordpress.org/plugins/syntaxhighlighter/

4
  • 1
    [code language="cpp"] your code here [/code] m also trying this way but getting same result. And my blog isn't self hosting, so i have no plugins using option. Commented Jan 14, 2015 at 15:22
  • Bear in mind that advice is for a hosted WordPress blog at wordpress.com, and much of it won't apply to WordPress hosted elsewhere. Commented Jan 14, 2015 at 15:22
  • @mattgibson noticed. But still he can install plugin from admin dashboard.
    – Jemshit
    Commented Jan 14, 2015 at 16:27
  • 1
    Wordpress' support for C++ is garbage. Might be better to use a preformatted block rather than deal with it trying to transform template <class T> into some kind of HTML tag
    – AndyG
    Commented Oct 30, 2018 at 17:29
1

I found a better way to post code in WordPress using gist. Create a public gist of your code, and copy the source link and paste to WordPress content.

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.