Posting source code on your posts

Posting source code on your posts
5 (100%) 1 vote

WordPress does not allow you to use potentially dangerous code on your blog, there is a way to post source code for viewing.
You can easily post syntax-highlighted code on your blog.

1. Install https://wordpress.org/plugins/syntaxhighlighter/ plugin

2. In your wodpress text editor just wrap your code in these tags:

[  code lang=”js”]
your code here
[/code]

Code in between the source code tags will automatically be encoded for display, you don’t need to worry about HTML entities or anything.

Setting parameters

lang – The language (or lang) parameter controls how the code is syntax highlighted. The following languages are supported: css, html, java, javascript, perl, php

If the language parameter is not set, it will default to “text” (no syntax highlighting).

autolinks (true/false) — Makes all URLs in your posted code clickable. Defaults to true.

collapse (true/false) — If true, the code box will be collapsed when the page loads, requiring the visitor to click to expand it. Defaults to false.

gutter (true/false) — If false, the line numbering on the left side will be hidden. Defaults to true.

highlight (comma-seperated list of numbers) — You can list the line numbers you want to be highlighted. For example “1,5”.

title (string) — Set a label for your code block. Can be useful when combined with the collapse parameter.

More settings here

Leave a Reply

Your email address will not be published. Required fields are marked *