Category Archives: Code Snippets

WordPress Plugin Skeleton

Here’s a foundation for writing a WordPress plugin, based on version 3.2. This would go in the main my-plugin-name.php file.

Posted in Code Snippets | Tagged , | Leave a comment

Escaping shortcodes in WordPress Posts

If you want to display the shortcode literally in a post (like so: [shortcode]), just use double brackets like this: “[[shortcode]]”. You can also use the html entities [ for “[" and ] for "]” (which you’ll need to use … Continue reading

Posted in Code Snippets | Tagged | Leave a comment

Javascript Function Skeleton

(function(){ var functionName = function(){ this.init(); }; functionName.prototype = { init : function() { this.setFunction(); }, setFunction : function() { // do stuff here } }; new functionName(); })();

Posted in Code Snippets | Tagged | Leave a comment

Focus First Input Field

Here’s a handy little snippet to automatically put the cursor in the first input field on the page. You can override it by adding a class of “nofocus” to any element and/or list the elements in the array. Nice for … Continue reading

Posted in Code Snippets | Tagged | Leave a comment

Generate Excerpt

Here’s a little snippet for generating an excerpt without breaking up a word: function excerpt($string=”, $maxChar=50, $uri=’#') { $length = strlen($string); if ($length < $maxChar) { return $string; } $trimmedString = substr($string, 0, $maxChar); $choppedString = substr($trimmedString, 0, strrpos($trimmedString, strrchr($trimmedString, … Continue reading

Posted in Code Snippets | Tagged | Leave a comment