Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Register callback function for post_thumbnail_html filter hook */
- add_filter( 'the_content', 'post_image_alt_change', 10, 5 );
- /* Function which will replace alt atribute to post title */
- function post_image_alt_change( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
- $post_title = get_the_title();
- $postcategories = get_the_category();
- $post_category='';
- if ($postcategories) {
- foreach($postcategories as $category) {
- $post_category .= $category->name .' ';
- }
- }
- $post_alt = $post_title . ' ' . $post_category;
- $html = preg_replace( '/(alt=")(.*?)(")/i', '$1'.esc_attr( $post_alt ).'$3', $html );
- return $html;
- }
Advertisement
Add Comment
Please, Sign In to add comment