= 2 || $page >= 2 ) $title = "$title $sep " . sprintf( __( 'Page %s', 'mckinley' ), max( $paged, $page ) ); return $title; } add_filter( 'wp_title', 'mckinley_wp_title', 10, 2 ); if ( ! function_exists( 'mckinley_the_attached_image' ) ) : /** * Prints the attached image with a link to the next attached image. * * @since McKinley 1.0 * * @return void */ function mckinley_the_attached_image() { $next_id = false; $post = get_post(); $attachment_size = apply_filters( 'mckinley_attachment_size', array( 724, 724 ) ); $next_attachment_url = wp_get_attachment_url(); if ( $post->post_parent ) { /** * Grab the IDs of all the image attachments in a gallery so we can get the URL * of the next adjacent image in a gallery, or the first image (if we're * looking at the last image in a gallery), or, in a gallery of one, just the * link to that image file. */ $attachment_ids = get_posts( array( 'post_parent' => $post->post_parent, 'fields' => 'ids', 'numberposts' => 999, '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 ( is_countable( $attachment_ids ) && count( $attachment_ids ) > 1 ) { foreach ( $attachment_ids as $idx => $attachment_id ) { if ( $attachment_id == $post->ID ) { $next_id = $attachment_ids[ ( $idx + 1 ) % count( $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( '%3$s', esc_url( $next_attachment_url ), the_title_attribute( array( 'echo' => false ) ), wp_get_attachment_image( $post->ID, $attachment_size ) ); } endif; /** * Returns the URL from the post. * * @uses get_url_in_content() to get the URL in the post meta (if it exists) or * the first link found in the post content. * * Falls back to the post permalink if no URL is found in the post. * * @since McKinley 1.0 * * @return string The Link format URL. */ function mckinley_get_link_url() { $content = get_the_content(); $has_url = get_url_in_content( $content ); return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); } /** * Extends the default WordPress body classes. * * Adds body classes to denote: * 1. Single or multiple authors. * 2. Active widgets in the sidebar to change the layout and spacing. * 3. When avatars are disabled in discussion settings. * * @since McKinley 1.0 * * @param array $classes A list of existing body class values. * @return array The filtered body class list. */ function mckinley_body_class( $classes ) { if ( ! is_multi_author() ) $classes[] = 'single-author'; if ( ! get_option( 'show_avatars' ) ) $classes[] = 'no-avatars'; return $classes; } add_filter( 'body_class', 'mckinley_body_class' ); /** * Adjusts content_width value for video post formats and attachment templates. * * @since McKinley 1.0 * * @return void */ function mckinley_content_width() { global $content_width; if ( is_attachment() ) $content_width = 724; elseif ( has_post_format( 'video' ) ) $content_width = 1000; elseif ( has_post_format( 'audio' ) ) $content_width = 484; } add_action( 'template_redirect', 'mckinley_content_width' ); /** * Gets gallery attachments from post content * * @param int $post Post ID or object. * @return mixed False on failure, array with attachment objects on success * @since McKinley 1.0 */ function mckinley_get_gallery_attachments( $post = null ) { $post = get_post( $post ); if ( !$post ) return false; $gallery_attachments = array(); $pattern = get_shortcode_regex(); preg_match_all( "/$pattern/s", $post->post_content , $matches, PREG_SET_ORDER ); if ( !empty( $matches ) ) { foreach ( $matches as $match ) { if ( $match[2] == 'gallery' ) { // allow [[gallery]] syntax for escaping a tag if ( !( $match[1] == '[' && $match[6] == ']' ) ) { $attr = shortcode_parse_atts( $match[3] ); if ( ! empty( $attr['ids'] ) ) { // 'ids' is explicitly ordered, unless you specify otherwise. if ( empty( $attr['orderby'] ) ) $attr['orderby'] = 'post__in'; $attr['include'] = $attr['ids']; } if ( isset( $attr['orderby'] ) ) { $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( !$attr['orderby'] ) unset( $attr['orderby'] ); } $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'include' => '', 'exclude' => '' ); $args = wp_parse_args( $attr, $defaults ); extract( $args ); $id = intval( $id ); if ( 'RAND' == $order ) $orderby = 'none'; if ( !empty( $include ) ) { $_attachments = get_posts( array( 'include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); $attachments = array(); foreach ( $_attachments as $key => $val ) { $attachments[$val->ID] = $_attachments[$key]; } } elseif ( !empty( $exclude ) ) { $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); } else { $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); } if ( !empty( $attachments ) ) $gallery_attachments[] = $attachments; } } } } if ( !empty( $gallery_attachments ) ) return $gallery_attachments; else return false; } /** * Removes standard gallery from gallery post format content. * * @since McKinley 1.0 */ function mckinley_strip_gallery($content) { $format = get_post_format(); if ( 'gallery' === $format ) { $pattern = get_shortcode_regex(); preg_match('/'.$pattern.'/s', $content, $matches); if ( isset($matches[2]) && is_array($matches) && $matches[2] == 'gallery') { //shortcode is being used $content = str_replace( $matches['0'], '', $content ); $content = wp_kses_post( $content ); } } return $content; } add_filter('the_content','mckinley_strip_gallery'); /** * Removes paragraph tag on images * * @since McKinley 1.0 */ function mckinley_filter_ptags_on_images($content){ return preg_replace('/

\s*()?\s*()\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content); } add_filter('the_content', 'mckinley_filter_ptags_on_images');