add_filter on specific page templates
-
Hi. First post… of many, I’m sure.
I’ve got a custom template for a single page, inside a custom theme. On this page I want to muck about with the default image tag that WP is outputting.
I think I understand filters, and have the following function (copied from another site; when I get it working I’ll make it do stuff other than tweaking the alt attribute):
function my_image_tag($html, $id , $alt, $title){ $html = str_replace('alt=""','alt="'.$title.'"',$html); return $html; }
I’ve added that to a plugin file, and activated the plugin.
I’ve also added the following call to the template file (at the top, before the have_posts() loop):
remove_filter ('the_content', 'wpautop'); add_filter('get_image_tag','my_image_tag',10,4);
(I removed the wpautop filter as I don’t want WP wrapping my content in p tags)
It doesn’t seem to be working. The default image tag (wrapped in an anchor tag, etc) is still present.
I’ve also tried moving the my_image_tag() filter function into a functions.php file in the theme dir (and disabling the plugin). Again, no filtering seems to be taking place.
What am I failing to understand?
- The topic ‘add_filter on specific page templates’ is closed to new replies.