' . "\n" . '' . "\n" . '' . "\n" . ''; } add_action('wp_head', 'wk_add_shim'); /** * Add Custom Header BG */ function wk_add_headerbg() { if (get_theme_mod('header_image') != null) : echo ''; endif; } add_action('wp_head', 'wk_add_headerbg'); /** * Extend 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 1.0.0 * @param array $classes * @return array */ function wk_body_class($classes) { if (!is_multi_author()) { $classes[] = 'single-author'; } if (is_active_sidebar('sidebar-primary') && !is_attachment() && !is_404()) { $classes[] = 'sidebar'; } if (!get_option('show_avatars')) { $classes[] = 'no-avatars'; } if (is_archive() || is_search() || is_home()) { $classes[] = 'list-view'; } if (is_singular() && !is_front_page()) { $classes[] = 'singular'; } return $classes; } add_filter('body_class', 'wk_body_class'); /** * Extend the default WordPress post classes. * Adds a post class to denote: * Non-password protected page with a post thumbnail. * @since 1.0.0 * @param array $classes * @return array */ function wk_post_classes($classes) { if (!post_password_required() && !is_attachment() && has_post_thumbnail()) { $classes[] = 'has-post-thumbnail'; } return $classes; } add_filter('post_class', 'wk_post_classes'); /** * return $images_id array() */ function wk_get_gallery_attachments() { global $post; $post_content = $post->post_content; $ids = array(); preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); if (!empty($ids)) : $images_id = explode(",", $ids[1]); else : $images_id = array(); endif; return $images_id; } /** * Strip shortcode gallery * @param type $content * @return type */ function wk_strip_shortcode_gallery($content) { preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER); if (!empty($matches)) { foreach ($matches as $shortcode) { if ('gallery' === $shortcode[2]) { $pos = strpos($content, $shortcode[0]); if ($pos !== false) return substr_replace($content, '', $pos, strlen($shortcode[0])); } } } return $content; } /* Plugin Name: Extract Videos Plugin URI: http://www.danielhaim.com/ Description: Extract auto-embedded videos (e.g. WP oEmbeds) out of the_content(); and convert the embedded-video into a function call and a shortcode allowing you to take full control of your content. Echo shortcode inside the loop or single.php with or . Version: 1.0 Author: Daniel Haim Author URI: http://www.danielhaim.com/ Copyright (C) 2013 Daniel Haim Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // add parameter html5=1 to oembed YouTube requests as per // http://stackoverflow.com/questions/17747443/css-transform-translate-breaking-youtube-embedded-video // using modified version of code on http://www.alittleofboth.com/2013/06/modifying-youtube-video-display-in-wordpress/ add_filter('oembed_result', 'youtube_oembed_html5_parameter', 10, 3); function youtube_oembed_html5_parameter($data, $url, $args = array()) { // add &html5=1 parameter $data = preg_replace('/(youtube\.com.*)(\?feature=oembed)(.*)/', '$1?' . apply_filters("hyrv_extra_querystring_parameters", "feature=oembed&html5=1&") . 'rel=0$3', $data); return $data; } /** * Get attachment meta data * @param type $attachment_id * @return type * @since 1.0.0 */ function wk_get_attachment($attachment_id) { $attachment = get_post($attachment_id); return array( 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true), 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'href' => get_permalink($attachment->ID), 'src' => $attachment->guid, 'title' => $attachment->post_title ); } if (!function_exists('wk_posts_navigation')) : /** * Display navigation to next/previous post when applicable. * @since 1.0.0 */ function wk_posts_navigation() { // Don't print empty markup if there's nowhere to navigate. $previous = ( is_attachment() ) ? get_post(get_post()->post_parent) : get_adjacent_post(false, '', true); $next = get_adjacent_post(false, '', false); if (!$next && !$previous) { return; } ?> max_num_pages < 2) { return; } $paged = get_query_var('paged') ? intval(get_query_var('paged')) : 1; $pagenum_link = html_entity_decode(get_pagenum_link()); $query_args = array(); $url_parts = explode('?', $pagenum_link); if (isset($url_parts[1])) { wp_parse_str($url_parts[1], $query_args); } $pagenum_link = remove_query_arg(array_keys($query_args), $pagenum_link); $pagenum_link = trailingslashit($pagenum_link) . '%_%'; $format = $wp_rewrite->using_index_permalinks() && !strpos($pagenum_link, 'index.php') ? 'index.php/' : ''; $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit($wp_rewrite->pagination_base . '/%#%', 'paged') : '?paged=%#%'; // Set up paginated links. $links = paginate_links(array( 'base' => $pagenum_link, 'format' => $format, 'total' => $wp_query->max_num_pages, 'current' => $paged, 'mid_size' => 1, 'add_args' => array_map('urlencode', $query_args), 'prev_text' => __(' Previous', 'wk'), 'next_text' => __('Next ', 'wk'), )); if ($links) : ?> | |
$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;