The most notable issue with our shortcode is that it doesn't discriminate against PHP and other functions (yet). Some time back we shared an article that retrieved all PHP and WordPress functions into an array; the original purpose of that function was designed to determine where to best link our embedded function references. In the end it wasn't practical so we walked away from it. Know a solution? Let us know.
The shortcode of
[php file="sample.txt"] returns the following function (the referenced function was borrowed from this article).
Note the very intentional similarity to Crayon's default styling. This rationalization was intentional to ensure a seamless experience across our website.
You may return a chunk of code. For example, to print line 27 through 30 I'd use
[php file="sample.txt" start="27" end="30"]. For the purpose of a demonstration, I can choose to alter the
$string color by using
[php file="sample.txt" start="27" end="30" string="#008000"] (close to the Crayon default). The result:
If you're using the function as previously provided on Internoetics you'll note that the download link is missing. The retired download link would automatically zip the file and record statistical data before the file was returned to a user. Since then, we've implemented our own file manager.
- Previously published on Internoetics as "Using PHP's highlight_file() Function in WordPress (with Automatic Zipping, Download Links, & Logging)". We've removed the features described in that title for simplicity.
- See also: "PHP's Syntax highlight_file() Function with Line Numbers and Alternating Coloured Rows" here.
- We continue to use Crayon but we use our shortcode highlghter when importing snippets from websites such as Snipplr.
Note, 3rd November, 2020: We now use this highlight code site-wide for reasons discussed in this article. There are still some issues but it is a superior solution since because we control the product, and it is lightning fast.
To download this plugin you must be logged in. If you're following us on Facebook or you're subscribed to our mailing list we've sent you a download link directly.