Taxonomy Images 0.6 Snippets

Posted on

By Michael Fields

Here are a bunch of examples about how you can customize the display of the Taxonomy Images plugin. It has been completely rewritten and there are many filters that you can use in your theme to make it look just right.

If you are not familiar with this plugin, please head on over to the WordPress Plugin Directory and check it out.

Custom Filters

The following snippets pertain to the taxonomy_image_plugin_image_list() action as well as the function of the same name. You can place these filters in your theme’s functions file.

Use div instead of the default ul tag for all taxonomy lists.

/**
 * Change the "ul" element in taxonomy_image_plugin_image_list()
 * to "div" for all taxonomy lists.
 */
function mytheme_taxonomy_image_plugin_list_element() {
	return 'div';
}
add_filter( 'taxonomy_image_plugin_list_element', 'mytheme_taxonomy_image_plugin_list_element' );

This simple filter allows you to change the name of the html element used to wrap the generated list of images. The following values can be used in such a filter: ol, ul, p, div. If any other value is passed, the default value of ul will be used.

Use p instead of ul for tags only.

/**
 * Change the "ul" tags in taxonomy_image_plugin_image_list()
 * to "p" tags for the "post_tag" taxonomy only.
 */
function mytheme_taxonomy_image_plugin_list_element_post_tag() {
	return 'p';
}
add_filter( 'taxonomy_image_plugin_list_element_post_tag', 'mytheme_taxonomy_image_plugin_list_element_post_tag' );

If have extended the filters to recognize individual taxonomies enabling each list to be filtered individually. In the above example, the post_tag taxonomy is singled out and its terms will now be wrapped in a paragraph. All other taxonomy lists will be left alone.

Use span instead of li for all lists.

/**
 * Change the default "li" element in taxonomy_image_plugin_image_list()
 * to "span" for all taxonomy lists.
 */
function mytheme_taxonomy_image_plugin_list_item_element() {
	return 'span';
}
add_filter( 'taxonomy_image_plugin_list_item_element', 'mytheme_taxonomy_image_plugin_list_item_element' );

Add a class of thickbox to all links in category lists.

/**
 * Add a class of "thickbox" to all linked images only in the category taxonomy.
 */
function mytheme_images_plugin_list_item_link_add_thickbox_class( $atts ) {
	$atts['class'] = 'thickbox';
	return $atts;
}
add_filter( 'taxonomy_image_plugin_list_item_link_atts_category', 'mytheme_images_plugin_list_item_link_add_thickbox_class' );

Force all image links to open in a new browser window.

/**
 * Force all image links to open in a new browser window.
 */
function mytheme_images_plugin_list_item_link_add_target_blank( $atts ) {
	$atts['target'] = '_blank';
	return $atts;
}
add_filter( 'taxonomy_image_plugin_list_item_link_atts', 'mytheme_images_plugin_list_item_link_add_target_blank' );

Remove the title attribute from all links.

/**
 * Remove the title attribute from all links.
 */
function mytheme_images_plugin_list_item_link_remove_title_attribute( $atts ) {
	unset( $atts['title'] );
	return $atts;
}
add_filter( 'taxonomy_image_plugin_list_item_link_atts', 'mytheme_images_plugin_list_item_link_remove_title_attribute' );

Share your thoughts

*

Fork me on GitHub