Ready to get started?Download WordPress


[resolved] filtering "wp_get_attachment_image_attributes" fails (4 posts)

  1. helgatheviking
    Posted 3 years ago #

    on line 659 of includes/media.php i found an interesting filter

    $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment );

    i thought i'd use it to try out some things I am working regarding serving responsive images. i thought i knew how to filter, but even just trying to pass the array of attributes (unchanged) back to the filter produces

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ' kia_attachment_attributes' not found or invalid function name in *****\wp-includes\plugin.php on line 166

    normally i get this error when i mismatch the name of the function with the name of the function being added to the filter, but i've copied and pasted them and they're the same. here is my code:

    function kia_attachment_attributes($attr) {
    	return $attr;
    add_filter('wp_get_attachment_image_attributes', ' kia_attachment_attributes', 10, 2 );
  2. Curtiss Grymala
    Posted 3 years ago #

    In the code you provided above, there is a space between the opening ' and the name of the function. Is that the way it is in your code, as well? If so, that's probably why you're getting the error.

  3. helgatheviking
    Posted 3 years ago #


    boy do i feel dumb. thank you so much for solving that for me! i looked right over that.

  4. Curtiss Grymala
    Posted 3 years ago #

    Happens to me all the time. :)

Topic Closed

This topic has been closed to new replies.

About this Topic