Suppose you want to add the following code snippet in PHP into your post.
You can either add it directly into the post which will probably mess up the formatting and reduce the readability ad shown below
<?php $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID, 'exclude' => get_post_thumbnail_id() ); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $attachment) { the_attachment_link($attachment->ID, false); } } ?>
Or you can use a syntax highlighting system which will make the code much more easier to read and understand.
Consider the following few code snippets
Snippet 1
Snippet 2
You will notice that each one of them has syntax highlighting but is formatted differently.
The author of the post will definitely know which language the code snippet is written in.
While adding the code snippet to the post the author can easily set the language so that it is formatted correctly using the language attribute of the short code as shown below
[ code language="php" custom="code1"][ /code]
Make sure you don’t enter the wrong language. Entering the wrong language may cause the code snippet not to show up in certain cases.
Related posts:

