Ajax is a great method for loading new content onto a web page without having to do an entire page refresh. It’s sometimes used in WordPress themes for paging, loading in full content after an excerpt, or dynamically displaying new comments as they are posted.
Ajax can also be used to load more significant amounts of content, but it gets more complicated. URLs don’t update by default, which is important if someone wants to bookmark that particular post or share it. Browser navigation buttons for “Back” and “Forward” can also be an issue.
Thankfully there are HTML5 methods for dealing with browser history and states, and an awesome jquery plugin that provides some fallback for older browsers. This tutorial will walk you through the code required for a theme that makes extensive use of ajax and also point you to some live demos.
Tim Thumb Hacker
Several of my websites were hacked this week using the TimThumb exploit. The issue has been known for a couple weeks now.
Although I had updated the majority of sites and had notified former clients, I still hadn’t gotten to some of the smaller sites yet- like my girlfriend’s food blog.
And word to the wise, your girlfriend’s food blog should always be top priority.
Hackers are using a variety of techniques to hijack WordPress sites right now, but this is how I cleaned up the ones on my server.
Occasionally a plugin or theme will need to display a notice to users in the WordPress dashboard. This is fairly easy to do using the admin_notices hook, which shows a standard message box at the top of the screen.
Example Admin Notices
Checkboxes are one of the more difficult form elements to deal with. For one, checkboxes don’t get sent in $_POST request unless they are checked. Any other element, like a text input or a radio button, will get sent regardless of it’s state. But if someone were to uncheck an option form and send it there would be no indication in the $_POST request that its state had changed. Read more
Sometimes you want to detect new users on your site versus returning visitors and display different sorts of information to them. An easy way to do this is to set a cookie. Read more
For my projects on GitHub I like to have the most recent stable version tagged so that people have an easy download link to it. So when I go from versions 0.4 > 0.5 on project (for instance), I do this:
1) Delete the v0.4 tag locally:
git tag -d v0.4
2) Delete the v0.4 tag on GitHub (which removes its download link):
git push origin :v0.4
3) Add a new tag for the newest stable release:
git tag -a v0.5 -m "Version 0.5 Stable"
4) Push the latest tag to GitHub (two dashes):
git push --tags
You can’t assume everyone is running the latest version of WordPress, especially around big point releases.
Simple Version Check
If you want your code to be backwards compatible (keep it within reason), you can do a simple WordPress version check with conditionals by using:
Or just use the global variable $wp_version.
Explanation of Excerpts
There’s two ways main ways to display posts on the home page and archive pages in WordPress. The first is to use the_excerpt tag, which checks to see if an excerpt has been manually entered. If it has, WordPress will display it. If it hasn’t, it’ll take the first 55 words from the post and display that instead.
Using the_excerpt is a perfect way to display a tiny snippet of the post so people can easily scroll through all the topics. When using the_excerpt, WordPress will also automatically remove any images or html tags that might mess with the layout in a shortened version.
I recently updated Portfolio Press to use new icons for its custom post type. The previous icon worked fine, but it didn’t exactly match the rest of WordPress core. I was also lucky enough to have Ben Dunkle, the designer who created the current set of core WordPress icons, offer to make me a new one.
I have a zip file of the icons I used (in psd format) which also has some other options we considered (briefcase, nicer weird eyeball) and the png files of the final choice. Feel free to use this in your own projects that need a portfolio icon. You can download it here.
There’s also a great collection of free custom post type icons available here for download which might have other icons you might be looking for.
I’m working on a WordPress theme project where the background needs to change randomly on each page load. To do this I added a body_class that generates a random number between 0 and 5 for me to use for styling (e.g. .random-1, random-2).
Just thought I’d post the snippet in case anyone was looking for something similar:
This video tutorial shows how to install WordPress on most any web host that uses cPanel, including BlueHost, InMotion, and HostGator. It shows how to upload the files, edit your wp-config.php file, create a database, create a database user, and then do the actual install.