'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'));
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');
/**
* Manage output of wp_title()
*/
function roots_wp_title($title) {
if (is_feed()) {
return $title;
}
$title .= get_bloginfo('name');
return $title;
}
add_filter('wp_title', 'roots_wp_title', 10);
/**
* Clean up output of stylesheet tags
*/
function roots_clean_style_tag($input) {
preg_match_all("!!", $input, $matches);
// Only display media if it is meaningful
$media = $matches[3][0] !== '' && $matches[3][0] !== 'all' ? ' media="' . $matches[3][0] . '"' : '';
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());
}
if (!is_front_page()) {
$classes[] = 'not-front';
}
// 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');
/**
* 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 Bootstrap thumbnail styling to images with captions
* Use