Widget Attributes

A while ago, I wrote about how you can add custom classes to your widgets. I’ve also created a plugin that’s available in WPORG but haven’t been updated in a while.

I’m announcing a new plugin, Widget Attributes, that you can use to add custom attributes to your widgets. Currently, it only supports the ID and classes and maybe will support adding custom attributes in the future. For now, you can download it from here. I’m submitting this plugin to WPORG and will retire the old one (I don’t like the name) and will update this post once it’s approved.

The plugin is now live!

WP-CLI on Gentoo

I recently encountered this error when running wp search-replace:

PHP Fatal error:  Call to undefined function cli\line() in …/wp-cli/vendor/wp-cli/php-cli-tools/lib/cli/Table.php on line 107

The FAQ says that you will need to install the php-process package, but there’s no such package nor USE flag in Gentoo. After some digging, I found out that the sysvipc and sharedmem are the USE flags that need to be added.

KC Settings Data

Just a quick note to those of you using KC Settings. As of version 2.6.8, all variables in kcSettings class have been merged and set to private. So if you’ve previously used kcSettings::$data, you will need to change your code to use the available method: kcSettings::get_data(). This static method behaves exactly like kc_get_option(), so you can put as many arguments (the array keys) as you like there to get the data you need, for example:

kcSettings::get_data('settings', 'plugin', 'myprefix', 'mysection')

Add HTML Tags in Post and Widget Titles

In a recent project, I needed to use <span /> tags to add some styles (just color, actually) to post and widget titles. By default — and there’s no hook to disable this — WordPress strips any HTML tags found in post and widget titles. Here’s my solution to this problem. Please keep in mind that I only needed to add <span /> tags, so if you need to add more tags, you should modify the code to fit your needs :) Continue reading →

wp_list_pages() for Custom Post Types

wp_list_pages() is a handy little function for displaying a list of hierarchical post type, and it works with custom post types too. Unfortunately, when used for a custom post type, the list items don’t have the necessary CSS classes for current page item/ancestors. Here’s a quick fix for this particular problem.

function kct_page_css_class( $css_class, $page, $depth, $args ) {
  if ( empty($args['post_type']) || !is_singular($args['post_type']) )
    return $css_class;

  $_current_page = get_queried_object();

  if ( in_array( $page->ID, $_current_page->ancestors ) )
    $css_class[] = 'current_page_ancestor';
  if ( $page->ID == $_current_page->ID )
    $css_class[] = 'current_page_item';
  elseif ( $_current_page && $page->ID == $_current_page->post_parent )
    $css_class[] = 'current_page_parent';

  return $css_class;
add_filter( 'page_css_class', 'kct_page_css_class', 10, 4 );