QuickStart

This tutorial shows highlighting PHP, however, WP-Syntax supports highlighting over 100 different languages.

Let’s start with highlighting some code:

This is what you would put in the post editor:

<pre lang="php">
<?php
function foo() {
    echo "Hello World!\\n";
}
?>

This is the code highlighted:

<?php
function foo() {
    echo "Hello World!\\n";
}
?>

Now, let’s add the line numbers using the “line” option:

This is what you would put in the post editor:

<pre lang="php" line="1">
<?php
function foo() {
    echo "Hello World!\\n";
}
?>

This is the code highlighted:

1
2
3
4
5
<?php
function foo() {
    echo "Hello World!\\n";
}
?>

To change the number that line numbers start at, use the “line” option, but change “1” to the number you wish to start with:

This is what you would put in the post editor:

<pre lang="php" line="18">
<?php
function foo() {
    echo "Hello World!\\n";
}
?>

This is the code highlighted:

18
19
20
21
22
<?php
function foo() {
    echo "Hello World!\\n";
}
?>

Ok, now, let’s highlight a specific line using the “highlight” option:

This is what you would put in the post editor:

<pre lang="php" line="18" highlight="3">
<?php
function foo() {
    echo "Hello World!\\n";
}
?>

This is the code highlighted:

18
19
20
21
22
<?php
function foo() {
    echo "Hello World!\\n";}
?>

Notice that you set the highlight value to the absolute line position and not the relative position.

Need to link to the source? Use the “src” option:

This is what you would put in the post editor:

<pre lang="php" line="18" highlight="3" src="https://github.com/shazahm1/Connections/blob/master/connections.php">
<?php
function foo() {
    echo "Hello World!\\n";
}
?>

This is the code highlighted:

/Connections/blob/master/connections.php
18
19
20
21
22
<?php
function foo() {
    echo "Hello World!\\n";}
?>