Tag Archives: Filter

The Walker_Comment class seems to be the weirdest and most hacked together of all the Walker classes in WordPress. Despite a few hours searching, I could not find a single example of a working Walker_Comment class anywhere on the entire internet. So I made this one from scratch by copying the default Walker_Comment function that comes with WordPress. It’s doing what I need it to, but I’m not 100% sure I’m using it properly.


Ignoring $output

Although the functions are set up to pass a global &$output variable forward, they don’t do it (at least in the default Walker class), they just echo each portion as it comes. It appears the Walker totally ignores the variable which just strikes me as odd.

start_lvl() Isn’t the Start

The start_lvl() function, with a $depth of 0 begins at each child comment, so essentially at the start of every reply which is the first to reach a new level under a particular comment. This took me awhile to figure out and is also rather odd. That’s why you have to wrap the comment list div/ol/ul yourself, because it has no way to reach the top of it’s own comments list.
I was able to wrap the comment list dynamically by just using the constructor and destructor functions, but I’m sure none of the other Walkers require that.


In the $args for wp_list_comments(), there are 2 optional callback functions which plug into start_el() and end_el() (I believe), so if you don’t need to play with any of the other functions, this is probably a less annoying way to accomplish this. I removed that plugged-in code from this example since there is no reason to ever do a custom Walker that refers to outside functions, just pick one or the other.

Anyway, here’s the code I finally came up with:Read More …

Aside from the standard Gravatar, WordPress allows users to choose from a list other default avatars. If you are creating your own theme, you can add an avatar or icon consistent with your theme’s styling to the list of default choices.

WordPress makes this a rather simple endeavor with the avatar_defaults filter. Add the code snippet below to a callback function (replace themeslug_ with your theme’s function slug) add an image of your choice to the list of avatars users can select from.

Although you can use any size, avatars of 60×60 pixels are the generally accepted size.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 …