's * Remove inline CSS used by Recent Comments widget * Remove inline CSS used by posts with galleries * Remove self-closing tag and change ''s to "'s on rel_canonical() */ function roots_head_cleanup() { // Originally from http://wpengineer.com/1438/wordpress-header/ remove_action('wp_head', 'feed_links', 2); remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); global $wp_widget_factory; remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style')); add_filter('use_default_gallery_style', '__return_null'); if (!class_exists('WPSEO_Frontend')) { remove_action('wp_head', 'rel_canonical'); add_action('wp_head', 'roots_rel_canonical'); } } function roots_rel_canonical() { global $wp_the_query; if (!is_singular()) { return; } if (!$id = $wp_the_query->get_queried_object_id()) { return; } $link = get_permalink($id); echo "\t\n"; } add_action('init', 'roots_head_cleanup'); /** * Remove the WordPress version from RSS feeds */ add_filter('the_generator', '__return_false'); /** * Clean up language_attributes() used in tag * * Change lang="en-US" to lang="en" * Remove dir="ltr" */ function roots_language_attributes() { $attributes = array(); $output = ''; if (function_exists('is_rtl')) { if (is_rtl() == 'rtl') { $attributes[] = 'dir="rtl"'; } } $lang = get_bloginfo('language'); if ($lang && $lang !== 'en-US') { $attributes[] = "lang=\"$lang\""; } else { $attributes[] = 'lang="en"'; } $output = implode(' ', $attributes); $output = apply_filters('roots_language_attributes', $output); return $output; } add_filter('language_attributes', 'roots_language_attributes'); /** * Clean up output of stylesheet tags */ function roots_clean_style_tag($input) { preg_match_all("!!", $input, $matches); // Only display media if it's print $media = $matches[3][0] === 'print' ? ' media="print"' : ''; return '' . "\n"; } add_filter('style_loader_tag', 'roots_clean_style_tag'); /** * Add and remove body_class() classes */ function roots_body_class($classes) { // Add post/page slug if (is_single() || is_page() && !is_front_page()) { $classes[] = basename(get_permalink()); } // Remove unnecessary classes $home_id_class = 'page-id-' . get_option('page_on_front'); $remove_classes = array( 'page-template-default', $home_id_class ); $classes = array_diff($classes, $remove_classes); return $classes; } add_filter('body_class', 'roots_body_class'); /** * Root relative URLs * * WordPress likes to use absolute URLs on everything - let's clean that up. * Inspired by http://www.456bereastreet.com/archive/201010/how_to_make_wordpress_urls_root_relative/ * * You can enable/disable this feature in config.php: * current_theme_supports('root-relative-urls'); * * @author Scott Walkinshaw */ function roots_root_relative_url($input) { // fix for site_url != home_url() if(!is_admin() && site_url() != home_url()) { $input = str_replace(site_url(), "", $input); } $output = preg_replace_callback( '!(https?://[^/|"]+)([^"]+)?!', create_function( '$matches', // If full URL is home_url("/") and this isn't a subdir install, return a slash for relative root 'if (isset($matches[0]) && $matches[0] === home_url("/") && str_replace("http://", "", home_url("/", "http"))==$_SERVER["HTTP_HOST"]) { return "/";' . // If domain is equal to home_url("/"), then make URL relative '} elseif (isset($matches[0]) && strpos($matches[0], home_url("/")) !== false) { return $matches[2];' . // If domain is not equal to home_url("/"), do not make external link relative '} else { return $matches[0]; };' ), $input ); return $output; } function roots_enable_root_relative_urls() { return !(is_admin() && in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) && current_theme_supports('root-relative-urls'); } if (roots_enable_root_relative_urls()) { $root_rel_filters = array( 'bloginfo_url', 'theme_root_uri', 'stylesheet_directory_uri', 'template_directory_uri', 'plugins_url', 'the_permalink', 'wp_list_pages', 'wp_list_categories', 'wp_nav_menu', 'the_content_more_link', 'the_tags', 'get_pagenum_link', 'get_comment_link', 'month_link', 'day_link', 'year_link', 'tag_link', 'the_author_posts_link', 'script_loader_src', 'style_loader_src' ); add_filters($root_rel_filters, 'roots_root_relative_url'); } /** * Wrap embedded media as suggested by Readability * * @link https://gist.github.com/965956 * @link http://www.readability.com/publishers/guidelines#publisher */ function roots_embed_wrap($cache, $url, $attr = '', $post_ID = '') { return '
' . $cache . '
'; } add_filter('embed_oembed_html', 'roots_embed_wrap', 10, 4); add_filter('embed_googlevideo', 'roots_embed_wrap', 10, 2); /** * Add class="thumbnail" to attachment items */ function roots_attachment_link_class($html) { $postid = get_the_ID(); $html = str_replace(' and
* * @link http://justintadlock.com/archives/2011/07/01/captions-in-wordpress */ function roots_caption($output, $attr, $content) { if (is_feed()) { return $output; } $defaults = array( 'id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '' ); $attr = shortcode_atts($defaults, $attr); // If the width is less than 1 or there is no caption, return the content wrapped between the [caption] tags if ($attr['width'] < 1 || empty($attr['caption'])) { return $content; } // Set up the attributes for the caption
$attributes = (!empty($attr['id']) ? ' id="' . esc_attr($attr['id']) . '"' : '' ); $attributes .= ' class="thumbnail wp-caption ' . esc_attr($attr['align']) . '"'; $attributes .= ' style="width: ' . esc_attr($attr['width']) . 'px"'; $output = ''; $output .= do_shortcode($content); $output .= '
' . $attr['caption'] . '
'; $output .= '
'; return $output; } add_filter('img_caption_shortcode', 'roots_caption', 10, 3); /** * Clean up gallery_shortcode() * * Re-create the [gallery] shortcode and use thumbnails styling from Bootstrap * * @link http://twitter.github.com/bootstrap/components.html#thumbnails */ function roots_gallery($attr) { $post = get_post(); static $instance = 0; $instance++; if (!empty($attr['ids'])) { if (empty($attr['orderby'])) { $attr['orderby'] = 'post__in'; } $attr['include'] = $attr['ids']; } $output = apply_filters('post_gallery', '', $attr); if ($output != '') { return $output; } if (isset($attr['orderby'])) { $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); if (!$attr['orderby']) { unset($attr['orderby']); } } extract(shortcode_atts(array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => '', 'icontag' => '', 'captiontag' => '', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => '' ), $attr)); $id = intval($id); if ($order === 'RAND') { $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)) { return ''; } if (is_feed()) { $output = "\n"; foreach ($attachments as $att_id => $attachment) { $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; } return $output; } $output = ''; return $output; } if (current_theme_supports('bootstrap-gallery')) { remove_shortcode('gallery'); add_shortcode('gallery', 'roots_gallery'); } /** * Remove unnecessary dashboard widgets * * @link http://www.deluxeblogtips.com/2011/01/remove-dashboard-widgets-in-wordpress.html */ function roots_remove_dashboard_widgets() { remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal'); remove_meta_box('dashboard_plugins', 'dashboard', 'normal'); remove_meta_box('dashboard_primary', 'dashboard', 'normal'); remove_meta_box('dashboard_secondary', 'dashboard', 'normal'); } add_action('admin_init', 'roots_remove_dashboard_widgets'); /** * Clean up the_excerpt() */ function roots_excerpt_length($length) { return POST_EXCERPT_LENGTH; } function roots_excerpt_more($more) { return ' … ' . __('Continued', 'roots') . ''; } add_filter('excerpt_length', 'roots_excerpt_length'); add_filter('excerpt_more', 'roots_excerpt_more'); /** * Remove unnecessary self-closing tags */ function roots_remove_self_closing_tags($input) { return str_replace(' />', '>', $input); } add_filter('get_avatar', 'roots_remove_self_closing_tags'); // add_filter('comment_id_fields', 'roots_remove_self_closing_tags'); // add_filter('post_thumbnail_html', 'roots_remove_self_closing_tags'); // /** * Don't return the default description in the RSS feed if it hasn't been changed */ function roots_remove_default_description($bloginfo) { $default_tagline = 'Just another WordPress site'; return ($bloginfo === $default_tagline) ? '' : $bloginfo; } add_filter('get_bloginfo_rss', 'roots_remove_default_description'); /** * Allow more tags in TinyMCE including