Change how wp-include functions work via template, please help! (2 posts)

  1. rgbk
    Posted 5 years ago #

    According to this post if i want to change a built-in function's behaviour, i need to:

    •Copy and paste the desired function into my template's functions.php file
    •Rename it.
    •Then add after that the following code:

    remove_filter('name_of_filter', 'name_of_function_to_change');
    add_filter('name_of_filter', 'name_of_new_function');

    I want to change the get_image_tag function inmedia.php so that width and height are removed.

    So I've copy and pasted this into my functions.php file:
    Note: this isn't tweaked yet, i'll do that after.

    	function mk_get_image_tag ($id, $alt, $title, $align, $size='medium') {
    	list( $img_src, $width, $height ) = image_downsize($id, $size);
    	$hwstring = image_hwstring($width, $height);
    	$class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;
    	$class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
    	$html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title).'" '.$hwstring.'class="'.$class.'" />';
    	$html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
    	return $html;

    But this is the part where i get confused:

    remove_filter('<strong>***********</strong>', 'get_image_tag');
    add_filter('<strong>***********</strong>', 'mk_get_image_tag');

    What does *********** refer too?
    I'm totally confused about how that affects the outcome?!
    Surely I just need to say:
    replace this function with my function
    Why do i have to do this with filters?

    Thanks a million.

  2. nouveller
    Posted 5 years ago #

    The first argument in both those functions probably wants to be 'the_content'. You can apply filters to any of these: http://codex.wordpress.org/Plugin_API/Filter_Reference.

Topic Closed

This topic has been closed to new replies.

About this Topic