Tag Archives: Php

I’ve exported all my WordPress PHP snippets from Dreamweaver using Massimo’s Snippet Import/Export extension.

I have about 50 of the most common theme related functions and pasted a lot of information from the WordPress codex in the descriptions. You can download mine here (tar.gz) (zip).

If anyone would like to contribute similar WordPress snippets, I’ll be glad to add them to the library.

If you want to get some of your social media statistics for a particular URL, like the number of Facebook “likes,” mentions on Twitter, or +1’s on Google Plus, you can (at least in theory). Facebook’s Open Graph API supports public like/share counts the best and in the easiest way. Twitter still allows you to do it by calling an internal JavaScript, and Google+ has no even semi-official way to do this, which is really uncharacteristic of them.

Google even took measures to disable the “unofficial” API method, so the only way to do it at the moment is to rip the number out of the official Google+ button’s source code with a regular expression. You can complain on this issue ticket and if enough people do, they might actually listen.

In any case, here are the good, the bad, and the ugly:Read More …

This is the most detailed tutorial in the world (to my knowledge) on the topic of creating a WordPress theme from scratch. If you read it all, you will know everything you need to create a complete and powerful WordPress theme. The verbosity of this tutorial means it can be tailored to people of any skill level, from ace theme jockey to complete and utter beginner.

I even go so far as to break down the basics of HTML and CSS, so I do mean beginner. However, I realize not everyone needs this much detail, so I have also included links to skip past beginner sections for those are so inclined.

Twilio is a great service. It allows you to send and receive automated calls and text messages for very reasonable prices. They also have a wonderful API that makes integration into your site or plugin a breeze.


You are given a unique Account SID and Account Token for each phone number you use; you use this data to authenticate with the server. To send a request, you just put To, From, and Body URL attributes into a HTTP post. The easiest way to do this is probably using cURL (or create stream). The function below is all you need to send an SMS.Read More …

A Quick Foreword

WordPress is fantastic, and it’s constantly improving. I think it’s amazing that the most powerful and popular CMS is open source and free. The massive community effort that continues to make WordPress’s so fantastic is actually quite astounding if you’ve ever taken a minute to consider it’s scope. It’s a shining example of the way software and the web writ large could be.

However, like all large projects, there is a lot on the agenda; and coordinating a decentralized army of volunteers is always going to get messy. With limited time and resources, you have to tackle the high priority issues first, and that list never really gets any shorter. That’s just the reality of the situation. Automattic doesn’t have an army of bright eyed recent CS grads they can lock in a basement with Mountain Dew and Skittles until every last issue has been dealt with. This means ideas and solutions, even the really good ones, can take a long time to make their way into the core.

The 3 Much-Needed Features

There are 3 problems that WordPress offers no clean way (at least that I’m aware of) to solve. I’ll explain them in more detail below, but in a nutshell they are:

  1. Lack of filters for widgets (design issue)
  2. No way to return the search_form if theme has a searchform.php file present(bug)
  3. No standardized way to get an attached image’s meta information, like: title, alt, description, or caption(laziness)

If you’ve ever coded the CSS and/or JavaScript needed to make a WordPress nav menu work smoothly across all browsers, you know how daunting that can be. Superfish is a jQuery plugin that is really ideal for WordPress’s multilevel navigation menus. Many themes make use of it, but (I’m assuming due to the lack of quality tutorials) few of them do it correctly. I will outline the correct procedure for adding Superfish, oh any other jQuery plugin to your theme.

Enqueue Scripts and Styles

Create a function that enqueues the necessary files. It’s generally a bad idea to replace WordPress’s native jQuery file, so don’t do it unless you absolutely must to make it work. I’ve included the (disabled) code to do it just in case you’re forced to.Read More …

The WP-Admin bar was added in version 3.1 of WordPress and it’s made the lives of many WordPress publishers a lot easier. The bar appears to logged in users with sufficient privileges on the front-end and dashboard of a WordPress blog. It offers easy navigation to different administrative tasks based on the type of page being viewed.

You can use this wonderful time saving tool to your advantage by adding custom links to the bar. This could be utilized by a theme or plugin to provide better access to a specialized functionality. The code below simply adds a constant link to the bar, but you could customize it further by adding different links when different conditionals to the add_action call.Read More …

I’ve also written a Custom Comment Walker function, after 3 hours of searching, I’m convinced it may be the only one out there lol…

If you’re trying to make a fancy navigation menu with CSS, you might have found the default IDs and classes applied by WordPress to the nav menu elements to be quite lacking. However, you can fix that by adding a custom walker function to add your own conditional classes. The custom nav walker function I made below will add the following CSS classes:

CSS Classes

  • .main-menu to top menu
  • .sub-menu to menus inside the main-menu
  • .menu-item to all <li>’s
  • .main-menu-item to all <li>’s in the main menu
  • .sub-menu-item to all <li>’s in a sub-menu
  • .sub-sub-menu to all menus inside a sub-menu
  • .menu-even/.menu-odd for <ul>’s (alternating)
  • .menu-depth-# to tell you how deep each menu is
  • .menu-item-even or .menu-item-odd (alternating)
  • .menu-item-depth-# to tell you which level menu the <li> is in
  • .menu-link to links

Optional Features

These requested features were can also be added to the code below. Click on each to be taken to the comment on this page describing how to integrate it.

This should make styling your Navigation Menus MUCH simpler.Read More …

If you’ve submitted a theme to the Review Unit recently, you may have gotten this feedback:

Themes are REQUIRED to use ‘wp_title’ filter, to filter wp_title() (RECOMMENDED), or pass argument to wp_title() (OPTIONALLY), in order to modify document title content.

At first I was like “um wat…” but then I realized it’s a much cleaner way to echo the title tag since it allows plugins or other code to get an equal bite at fully changing the page title (no hardcoded title parts in themes).

However, unlike most other WordPress theme topics, there is a real dearth of practical examples or even explanations on the internet about how to actually do this for some odd reason. The codex page is quite unhelpful and I Googled 10 pages deep and only found 1 passing mention. So I had to figure this out on my own the old-fashioned, pre-internet way: trial and error.Read More …