Highlighting current page in WordPress Menus
By default, wp_nav_menu doesn't create a .current_page_item or .current-menu-item class for certain elements in a wp_nav_menu, for example if you are viewing a custom post type archive or single page.
Here's some code to fix that. Bang it in functions.php
Don't forget to create your CSS classes if you already haven't done so.
Splitting WordPress content with ‘more’ on single pages
WordPress uses the "More" button to create a small snippet of content, usually used on the blog page, to create article teasers and such. WordPress ignores the "More" function on single posts, pages and several other pages.
Here's some code of make use of the "More" function on single pages and single posts. Perhaps splitting the content into columns or hiding extra content in an accordion or pretty much anything. Look, I'm going to press the "More" button right now.
[Snippet] Formatting the date in twitter XML feed
The date in the Twitter XML feed is daft and ugly! It reads [created_at] => Wed Aug 03 23:34:35 +0000 2011
We can easily format this with PHP using date() and strtotime()
Using the Twitter XML Feed in PHP
Parsing the Twitter XML feed for a user in PHP is now super simple.
- $username = 'Kieran_Barnes';
- $format = 'xml';
- $tweet = simplexml_load_file("http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}");
Disabling Core Dumps
I recently found a (cPanel) server was generating over 100Gb of core dumps every time a bad PHP script died or Apache died. Writing these generally useless (who actually debugs these on a live web server) to disk is a pointless waste of disk I/O, especially in a VPS environment.
Here is two methods of disabling core dumps;
Building rich experiences with xdebug javascript plugins
Ian Horst from PHPNW has posted a good article on Building rich experiences with xdebug javascript plugins which came about from a talk by Derick Rethans. It discusses making xdebug data available as JSON so you better understand the xdebug output. Hopefully this will become more wide spread in time.
Overview of PHP Handlers for cPanel
c
Panel provides four different PHP Handlers, some are good, some are not so good.
Here's a simple overview of the four options you have. Original site is currently down so I can't trackback.
Disabling Dangerous PHP Functions in a Shared Environment
PHP is an incredibly versatile language and if used in the wrong way, either maliciously or by accident has the potential to mess up an entire webserver. This can be a major problem if you are offering a shared hosting environment.
There is an often overlooked php.ini setting called disable_functions at hand.
Sorting a multidimensional array
PHP's sort() or asort() functions are only single dimensional. What happens when you need to sort a multidimensional array based on a specific key?
Use this.
Looping over dates in PHP
I recently had to loop over the difference between two dates.
For example to create checkboxes for individual dates within a date range? Should be simple, right?



