Skip to content

Instantly share code, notes, and snippets.

@markkap
Created June 8, 2016 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markkap/00a730c2a388187d8befe7ec38c49a63 to your computer and use it in GitHub Desktop.
Save markkap/00a730c2a388187d8befe7ec38c49a63 to your computer and use it in GitHub Desktop.
target the cpw_excerpt filter at a specific widget
/**
* This gist shows how to use the "number" attribute of a widget object to target a specific widget
* You can find the number associate with a specific widget by inspecting the generated HTML for it,
* it is the suffix of the id attribute of the element wrapping the widget
*
* @param string $excerpt The current excerpt
* @param WP_Widget $widget the widget object from which it is possible to get the information of its type an dID number
* @param int $length the configured request length for an excerpt. A zero is passed if no value is actually configured
*
* @return the widget number appended to the excerpt
*/
function cpw_excerpt_filter_wn($excerpt,$widget,$length) {
return $excerpt.' '.$widget->number;
}
add_filter('cpw_excerpt','cpw_excerpt_filter_wn',10,3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment