$post->post_parent, 'fields' => 'ids', 'numberposts' => -1, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', )); // If there is more than 1 attachment in a gallery... if (count($attachment_ids) > 1) { foreach ($attachment_ids as $attachment_id) { if ($attachment_id == $post->ID) { $next_id = current($attachment_ids); break; } } // get the URL of the next image attachment... if ($next_id) { $next_attachment_url = get_attachment_link($next_id); } // or get the URL of the first image attachment. else { $next_attachment_url = get_attachment_link(array_shift($attachment_ids)); } } printf('%2$s', esc_url($next_attachment_url), wp_get_attachment_image($post->ID, $attachment_size) ); } endif; /** * Extend the default WordPress body classes. * * Adds body classes to hAtom Schema purpose * No need for additional div wrapper * * @param array $classes A list of existing body class values. * @return array The filtered body class list. */ function bigblank_body_classes($classes) { $classes[] = (is_front_page()) ? 'site' : 'hfeed site'; return $classes; } add_filter('body_class', 'bigblank_body_classes'); /** * Create a nicely formatted and more specific title element text for output * in head of document, based on current view. * * * @param string $title Default title text for current view. * @param string $sep Optional separator. * @return string The filtered title. */ function bigblank_wp_title($title, $sep) { global $paged, $page; if (is_feed()) { return $title; } // Add the site name. $title .= get_bloginfo('name'); // Add the site description for the home/front page. $site_description = get_bloginfo('description', 'display'); if ($site_description && ( is_home() || is_front_page() )) { $title = "$title $sep $site_description"; } // Add a page number if necessary. if ($paged >= 2 || $page >= 2) { $title = "$title $sep " . sprintf(__('Page %s', 'bigblank'), max($paged, $page)); } return $title; } add_filter('wp_title', 'bigblank_wp_title', 10, 2); // This function adds nice anchor with id attribute to our h2 tags for reference // Ref: http://www.w3.org/TR/html4/struct/links.html#h-12.2.3 function bigblank_anchor_content_h2($content) { // Pattern that we want to match $pattern = '/

(.*?)<\/h2>/'; // now run the pattern and callback function on content $content = preg_replace_callback($pattern, // function to replace the title with an id function ($matches) { $title = $matches[1]; $slug = sanitize_title_with_dashes($title); return '

' . $title . '

'; } , $content); return $content; } add_filter('the_content', 'bigblank_anchor_content_h2'); /** * Filter

tags wrapping images * comment out if you wish to keep them in

tags. * \2 a tag open * \3 image tag * \6 a tag close * \n is the group of paranthesis returned * "generally, the results of the captured groups are in the order in which they * are defined (the open parenthesis)" * Exclude alignleft and alignright images, and also images middle of the * paragraphs. Also remove wrapping paragraph of images inside spans. * @link http://regexone.com/lesson/ * @link https://www.debuggex.com/r/Xt9Qvb0_3FKQc4BF */ function bigblank_replace_ptags_around_images_with_figure($content) { /* For images with default WordPress alignement */ $content = preg_replace('/\s?()?\s*()?\s*(]+class="(?:.+\s)?(aligncenter|alignnone|alignleft|alignright)(?:\s.+)?"([^"]+)".*>)\s*(<\/a>)?\s*(<\/span>)?\s*<\/p>/iU', '

\2\3\6
', $content); /* For images copied with formatting that does not follow WordPress alignement and everything else */ $content = preg_replace('/\s?()?\s*()?\s*(].*>)\s*(<\/a>)?\s*(<\/span>)?\s*<\/p>/iU', '
\2\3\6
', $content); return $content; } add_filter('the_content', 'bigblank_replace_ptags_around_images_with_figure'); /** * Filter

tags wrapping iframes and other embed elements * I know, I know.. Just following WordPress Coding Standards * @link http://make.wordpress.org/core/handbook/coding-standards/php/#clever-code * * @param string $content */ function bigblank_remove_ptags_around_embeds($content) { $content = preg_replace('/\s?(*.<\/object>)\s*<\/p>/iU', '\1', $content); $content = preg_replace('/\s?(*.<\/embed>)\s*<\/p>/iU', '\1', $content); $content = preg_replace('/\s?(