WordPress Change Default Number of Displayed Posts
By default, WordPress displays the same number of posts for the home page (when it is set to display posts) and all types of archive views. To change the default number of posts displayed for any specific view, you can add this simple function to your theme’s functions.php file.
PHP Shorten String by Character Count
Quick copy-n-paste function to truncate or shorten a string of text to a specific number of characters. Useful for things like “next” and “previous” navigation links and so forth.
CSS Dark Pre Tag Styles
Here is a quick CSS snippet for adding some smooth, dark styles to any <pre> tag. One-step snippet for complete pre styling: add to your stylesheet and done.
WordPress Shortcode Display Search Form
Here is an easy custom WordPress function to display your theme’s search form via shortcode. This makes it easy to display the search form on any Post or Page.
PHP Check if Request is HTTPS
Here we have a simple and effective PHP function that checks whether or not HTTPS (via SSL) is used for the current request.
CSS Viewport Tricks
Note to self: you can specify various viewport properties such as initial-scale and user-zoom via <meta /> tags or directly via CSS.
WordPress Prefix Post Titles
A reader recently asked how they can prepend the post date to the post title. Here is a quick and easy way to do it by filtering WordPress’ the_title hook.
jQuery Truncate Text
Here are a few choice code snippets to truncate text with jQuery. Useful for fine-tuning responsive layouts, or just truncating strings of text in general.
PHP foreach loop
I am always using this PHP code snippet, which basically loops through an array that may or may not include nested arrays. So to make things easier, I am posting here for quick reference.
WordPress repair and optimize InnoDB
This tutorial explains how to use WordPress’ built-in tools for optimizing database tables that are of the InnoDB type. Also works for good ’ol MyISAM database tables.
Force file download with .htaccess
Here is a quick .htaccess snippet that will force files to download instead of displaying in the browser. This method works for any site running on an Apache server.
CSS box-sizing all elements
The CSS box-sizing property makes it much easier to work with elements that have padding and borders. Here is a ruleset that will apply the box-size property to all elements.