Mihir
Mihir

Reputation: 8734

How to insert code into wordpress

In many wordpress blogs, we are seeing the code like below. enter image description here

Now I want to put my code also like this? How to do it? is it belongs to any thrid party tool or is it in built comes with wordpress? When I copy and paste the code into blog it looking ugly. Please give me suggestion to make my blog more readable. Thank you

Upvotes: 34

Views: 40136

Answers (6)

ScryptKeeper
ScryptKeeper

Reputation: 51

Latest: in edit post, start typing /syntax. Choose SyntaxHighligher. You can change the type of language in the block.

WordPress Help

Upvotes: 0

Deepak
Deepak

Reputation: 35

Do this if you want to add code in your wordpress post:

Switch to Text from HTML in your wordpress editor, then insert <code> as starting tag and </code> as end tag.

This is the only method that works in the latest wordpress at the time I am writing the answer. Have fun!

Upvotes: 2

HareRam
HareRam

Reputation: 764

If you are running your blog on Wordpress.com, you just include the following lines before your code.

[sourcecode language="csharp"]
//your code comes here
[/sourcecode]

Wordpress.com gives us the facility to avoid worrying about code highlighting. If your code is in between these blocks then it will automatically render as per the language you specified. It can support many languages.

Some of them are..

html

javascript

java

javafx

matlab (keywords only)

objc

perl

php

If you have a self-hosted site, or one hosted on wordpress.org, you should should use the SyntaxHighlighter plugin: wordpress.org/plugins/syntaxhighlighter.

This is the plugin the WordPress team sourced to create this functionality on wordpress.com

For more information see this link

Upvotes: 64

Sandeep Gupta
Sandeep Gupta

Reputation: 7250

Adding to SHEKHAR SHETE's answer.

For inline code blocks:

Selecting a text and then performing Alt+Shift+x will make text like:

THIS is an example

This will actually sorround the text with <code></code>

Writing text inside `..` is another way

source

Upvotes: 4

SHEKHAR SHETE
SHEKHAR SHETE

Reputation: 6066

Sorry to say, but with following code you mentioned WONT WORK

[sourcecode language="csharp"]
//your code comes here
[/sourcecode]

So, on Wordpress Site to add Code snippet to the wordpress blog is:

[code language="javascript"]
//your language script here
[/code]

Hope this helped you! :)

Upvotes: 19

CMoreira
CMoreira

Reputation: 1708

What you are looking for is some kind of syntax highlighter. Where the code shows up in your post in a box with the number of lines, etc, correct?

There are some plugins in wordpress for that.

Check out:

http://wordpress.org/extend/plugins/syntaxhighlighter/

http://wordpress.org/extend/plugins/crayon-syntax-highlighter/

Hope it helps. Cheers

Upvotes: 6

Related Questions