Want to customise the WordPress gallery html layout? Instead of overwriting the gallery shortcode function, a better way is to use the post_gallery filter that is included within that function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | add_filter('post_gallery','customFormatGallery',10,2); function customFormatGallery($string,$attr){ $output = "<div id=\"container\">"; $posts = get_posts(array('include' => $attr['ids'],'post_type' => 'attachment')); foreach($posts as $imagePost){ $output .= "<div src='".wp_get_attachment_image_src($imagePost->ID, 'small')[0]."'>"; $output .= "<div src='".wp_get_attachment_image_src($imagePost->ID, 'medium')[0]."' data-media=\"(min-width: 400px)\">"; $output .= "<div src='".wp_get_attachment_image_src($imagePost->ID, 'large')[0]."' data-media=\"(min-width: 950px)\">"; $output .= "<div src='".wp_get_attachment_image_src($imagePost->ID, 'extralarge')[0]."' data-media=\"(min-width: 1200px)\">"; } $output .= "</div>"; return $output; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.