DIY WordPress PHP shortcodes – Code Snippets plugin

code snippets plugin

I’m lovin’-this plug-in!

Example:

Print Friendly

Update: 6th March 2017

Days later: I’m already out-growing these snippets … as I’ve abandoned the WordPress plug-in for Syntaxhighlighter, and am now using the general client-side build cloned from GitHub, with a little extra hacked into the build-output currently for ajax (custom event), I’ve decided to make my own crude rudimentary plug-in just to contain a collection of functions etc. to deal with shortcodes for Syntaxhighlighter and ajax GitHub raw-file retrieval etc.

LOADING CODE FROM GITHUB VIA AJAX...
For the preg_replace regx stuff I used an online tool to help:
LOADING CODE FROM GITHUB VIA AJAX...

To self: useful links:
https://codex.wordpress.org/Template_Tags/get_posts
https://developer.wordpress.org/reference/functions/get_post/
https://codex.wordpress.org/Class_Reference/WP_Post

.tabcontents .pf-content .printfriendly
{
	display: none;
}
#colorbox .pf-content .printfriendly
{
	display: none;
}
    
In order to use this shortcode in menutab without an extra printfriendly button appearing, I added this CSS.

LOADING CODE FROM GITHUB VIA AJAX...

Using my github shortcode in combination with other plugin shortcodes:


<p style="clear:both;">...</p>
<span style="float:right;">[wp_colorbox_media url="#wp_colorbox_contactpagefooter" type="inline" hyperlink="" alt="CODE ZOOM"]</span>
<div class="xarta-code-style xarta-code-width xarta-code-buttons">
<div id="wp_colorbox_contactpagefooter">
[js title="https://raw.githubusercontent.com/davros1973/borg-contact/master/contactpagefooter.js" classname="xarta-big-code" light="1"]
[github raw='borg-contact/master/contactpagefooter.js']
[/js]
</div><code> </code></div>

nb: tried to show an ampersand nbsp; special character above, in-between the two closing </div> tags, but it doesn’t show-up here even in <code> tags and I don’t know why. Maybe it’s something to do with ASCII code 32 vs ASCII code 160?

And using my more advanced xgithub snippet (shown {hopefully} working below). I’m passing the “light” attribute (default = 1) with value “0” to the SyntaxHighlighter PlugIn.


[xgithub raw='borg-contact/master/contactpagefooter.js' lang='js' light='0' ]
LOADING CODE FROM GITHUB VIA AJAX...
Print Friendly