Using WordPress ‘get_avatar_comment_types’ PHP filter

The get_avatar_comment_types WordPress PHP filter allows you to modify the list of allowed comment types for retrieving avatars.

Usage

add_filter('get_avatar_comment_types', 'your_custom_function');
function your_custom_function($types) {
  // your custom code here
  return $types;
}

Parameters

  • $types (array): An array of content types. By default, it only contains ‘comment’.

More information

See WordPress Developer Resources: get_avatar_comment_types

Examples

Add a custom comment type to the allowed list

Add a custom comment type ‘review’ to the allowed list of comment types for retrieving avatars.

add_filter('get_avatar_comment_types', 'add_review_comment_type');
function add_review_comment_type($types) {
  $types[] = 'review';
  return $types;
}

Remove ‘comment’ type from the allowed list

Remove the default ‘comment’ type from the allowed list of comment types for retrieving avatars.

add_filter('get_avatar_comment_types', 'remove_comment_type');
function remove_comment_type($types) {
  unset($types[array_search('comment', $types)]);
  return $types;
}

Allow only custom comment types

Allow only custom comment types ‘review’ and ‘testimonial’ for retrieving avatars.

add_filter('get_avatar_comment_types', 'allow_only_custom_comment_types');
function allow_only_custom_comment_types($types) {
  $types = ['review', 'testimonial'];
  return $types;
}

Add multiple custom comment types

Add multiple custom comment types ‘review’, ‘testimonial’, and ‘feedback’ to the allowed list of comment types for retrieving avatars.

add_filter('get_avatar_comment_types', 'add_multiple_comment_types');
function add_multiple_comment_types($types) {
  array_push($types, 'review', 'testimonial', 'feedback');
  return $types;
}

Clear all allowed comment types

Clear all allowed comment types for retrieving avatars.

add_filter('get_avatar_comment_types', 'clear_allowed_comment_types');
function clear_allowed_comment_types($types) {
  $types = [];
  return $types;
}