0

the idea is apply some filters if the user select the option in the theme, but i have a problem

i made a function that replace the post_thumbnail_html for a personalized html

then, i create other function that create thumnails for timthumb

i'm trying to apply the add_filter to the timthumb function, but it doesn't work because is not a wordpress hook

can you helpme?

function kandombe_theme_thumb($id, $width, $height, $align='') {

        //some code

        $html = '<img class="archive_thumb" src='.$image_url.' width="'.$width.'" height="'.$height.'"/>';

        return $html;

    }

if ($data['speed_lazy_loading']) { 

    function kandombe_lazy_loads( $html ) {

        //some code

        $html = preg_replace( '#<img([^>]+?)src=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>#', sprintf( '<img${1}src="%s" data-original="${2}"${3} style="display: block;"><noscript><img${1}src="${2}"${3}></noscript>', $placeholder_image ), $html );

    return $html;
    }

add_filter( 'the_content', 'kandombe_lazy_loads');
add_filter( 'post_thumbnail_html', 'kandombe_lazy_loads');
add_filter( 'kandombe_theme_thumb', 'kandombe_lazy_loads');
add_filter( 'get_avatar', 'kandombe_lazy_loads');

}

1 Answer 1

1

Assuming that this-- add_filter( 'kandombe_theme_thumb', 'kandombe_lazy_loads');-- is the line/hook you are talking about.

You don't hook to functions. That is not how it works. Hooks have to be intentionally created with apply_filters or do_action. Your code would have to be written like this for that to work:

function kandombe_theme_thumb($id, $width, $height, $align='') {
    //some code
    $html = apply_filters(
      'kandombe_theme_thumb',
      '<img class="archive_thumb" src='.$image_url.' width="'.$width.'" height="'.$height.'"/>'
    );
    return $html;
}

Related

https://wordpress.stackexchange.com/a/103644/21376

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.