bones.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?php
  2. /* Welcome to Bones :)
  3. This is the core Bones file where most of the
  4. main functions & features reside. If you have
  5. any custom functions, it's best to put them
  6. in the functions.php file.
  7. Developed by: Eddie Machado
  8. URL: http://themble.com/bones/
  9. - head cleanup (remove rsd, uri links, junk css, ect)
  10. - enqueueing scripts & styles
  11. - theme support functions
  12. - custom menu output & fallbacks
  13. - related post function
  14. - page-navi function
  15. - removing <p> from around images
  16. - customizing the post excerpt
  17. - custom google+ integration
  18. - adding custom fields to user profiles
  19. */
  20. /*********************
  21. WP_HEAD GOODNESS
  22. The default wordpress head is
  23. a mess. Let's clean it up by
  24. removing all the junk we don't
  25. need.
  26. *********************/
  27. function bones_head_cleanup() {
  28. // category feeds
  29. // remove_action( 'wp_head', 'feed_links_extra', 3 );
  30. // post and comment feeds
  31. // remove_action( 'wp_head', 'feed_links', 2 );
  32. // EditURI link
  33. remove_action( 'wp_head', 'rsd_link' );
  34. // windows live writer
  35. remove_action( 'wp_head', 'wlwmanifest_link' );
  36. // previous link
  37. remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
  38. // start link
  39. remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
  40. // links for adjacent posts
  41. remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
  42. // WP version
  43. remove_action( 'wp_head', 'wp_generator' );
  44. // remove WP version from css
  45. add_filter( 'style_loader_src', 'bones_remove_wp_ver_css_js', 9999 );
  46. // remove Wp version from scripts
  47. add_filter( 'script_loader_src', 'bones_remove_wp_ver_css_js', 9999 );
  48. } /* end bones head cleanup */
  49. // A better title
  50. // http://www.deluxeblogtips.com/2012/03/better-title-meta-tag.html
  51. function rw_title( $title, $sep, $seplocation ) {
  52. global $page, $paged;
  53. // Don't affect in feeds.
  54. if ( is_feed() ) return $title;
  55. // Add the blog's name
  56. if ( 'right' == $seplocation ) {
  57. $title .= get_bloginfo( 'name' );
  58. } else {
  59. $title = get_bloginfo( 'name' ) . $title;
  60. }
  61. // Add the blog description for the home/front page.
  62. $site_description = get_bloginfo( 'description', 'display' );
  63. if ( $site_description && ( is_home() || is_front_page() ) ) {
  64. $title .= " {$sep} {$site_description}";
  65. }
  66. // Add a page number if necessary:
  67. if ( $paged >= 2 || $page >= 2 ) {
  68. $title .= " {$sep} " . sprintf( __( 'Page %s', 'dbt' ), max( $paged, $page ) );
  69. }
  70. return $title;
  71. } // end better title
  72. // remove WP version from RSS
  73. function bones_rss_version() { return ''; }
  74. // remove WP version from scripts
  75. function bones_remove_wp_ver_css_js( $src ) {
  76. if ( strpos( $src, 'ver=' ) )
  77. $src = remove_query_arg( 'ver', $src );
  78. return $src;
  79. }
  80. // remove injected CSS for recent comments widget
  81. function bones_remove_wp_widget_recent_comments_style() {
  82. if ( has_filter( 'wp_head', 'wp_widget_recent_comments_style' ) ) {
  83. remove_filter( 'wp_head', 'wp_widget_recent_comments_style' );
  84. }
  85. }
  86. // remove injected CSS from recent comments widget
  87. function bones_remove_recent_comments_style() {
  88. global $wp_widget_factory;
  89. if (isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) {
  90. remove_action( 'wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style') );
  91. }
  92. }
  93. // remove injected CSS from gallery
  94. function bones_gallery_style($css) {
  95. return preg_replace( "!<style type='text/css'>(.*?)</style>!s", '', $css );
  96. }
  97. /*********************
  98. SCRIPTS & ENQUEUEING
  99. *********************/
  100. // loading modernizr and jquery, and reply script
  101. function bones_scripts_and_styles() {
  102. global $wp_styles; // call global $wp_styles variable to add conditional wrapper around ie stylesheet the WordPress way
  103. if (!is_admin()) {
  104. // modernizr (without media query polyfill)
  105. wp_register_script( 'bones-modernizr', get_stylesheet_directory_uri() . '/library/js/libs/modernizr.custom.min.js', array(), '2.5.3', false );
  106. // register main stylesheet
  107. wp_register_style( 'bones-stylesheet', get_stylesheet_directory_uri() . '/library/css/style.css', array(), '', 'all' );
  108. // ie-only style sheet
  109. wp_register_style( 'bones-ie-only', get_stylesheet_directory_uri() . '/library/css/ie.css', array(), '' );
  110. // comment reply script for threaded comments
  111. if ( is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) {
  112. wp_enqueue_script( 'comment-reply' );
  113. }
  114. //adding scripts file in the footer
  115. wp_register_script( 'bones-js', get_stylesheet_directory_uri() . '/library/js/scripts.js', array( 'jquery' ), '', true );
  116. // enqueue styles and scripts
  117. wp_enqueue_script( 'bones-modernizr' );
  118. wp_enqueue_style( 'bones-stylesheet' );
  119. wp_enqueue_style( 'bones-ie-only' );
  120. $wp_styles->add_data( 'bones-ie-only', 'conditional', 'lt IE 9' ); // add conditional wrapper around ie stylesheet
  121. /*
  122. I recommend using a plugin to call jQuery
  123. using the google cdn. That way it stays cached
  124. and your site will load faster.
  125. */
  126. wp_enqueue_script( 'jquery' );
  127. wp_enqueue_script( 'bones-js' );
  128. }
  129. }
  130. /*********************
  131. THEME SUPPORT
  132. *********************/
  133. // Adding WP 3+ Functions & Theme Support
  134. function bones_theme_support() {
  135. // wp thumbnails (sizes handled in functions.php)
  136. add_theme_support( 'post-thumbnails' );
  137. // default thumb size
  138. set_post_thumbnail_size(125, 125, true);
  139. // wp custom background (thx to @bransonwerner for update)
  140. add_theme_support( 'custom-background',
  141. array(
  142. 'default-image' => '', // background image default
  143. 'default-color' => '', // background color default (dont add the #)
  144. 'wp-head-callback' => '_custom_background_cb',
  145. 'admin-head-callback' => '',
  146. 'admin-preview-callback' => ''
  147. )
  148. );
  149. // rss thingy
  150. add_theme_support('automatic-feed-links');
  151. // to add header image support go here: http://themble.com/support/adding-header-background-image-support/
  152. // adding post format support
  153. add_theme_support( 'post-formats',
  154. array(
  155. 'aside', // title less blurb
  156. 'gallery', // gallery of images
  157. 'link', // quick link to other site
  158. 'image', // an image
  159. 'quote', // a quick quote
  160. 'status', // a Facebook like status update
  161. 'video', // video
  162. 'audio', // audio
  163. 'chat' // chat transcript
  164. )
  165. );
  166. // wp menus
  167. add_theme_support( 'menus' );
  168. // registering wp3+ menus
  169. register_nav_menus(
  170. array(
  171. 'main-nav' => __( 'The Main Menu', 'bonestheme' ), // main nav in header
  172. 'footer-links' => __( 'Footer Links', 'bonestheme' ) // secondary nav in footer
  173. )
  174. );
  175. } /* end bones theme support */
  176. /*********************
  177. RELATED POSTS FUNCTION
  178. *********************/
  179. // Related Posts Function (call using bones_related_posts(); )
  180. function bones_related_posts() {
  181. echo '<ul id="bones-related-posts">';
  182. global $post;
  183. $tags = wp_get_post_tags( $post->ID );
  184. if($tags) {
  185. foreach( $tags as $tag ) {
  186. $tag_arr .= $tag->slug . ',';
  187. }
  188. $args = array(
  189. 'tag' => $tag_arr,
  190. 'numberposts' => 5, /* you can change this to show more */
  191. 'post__not_in' => array($post->ID)
  192. );
  193. $related_posts = get_posts( $args );
  194. if($related_posts) {
  195. foreach ( $related_posts as $post ) : setup_postdata( $post ); ?>
  196. <li class="related_post"><a class="entry-unrelated" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  197. <?php endforeach; }
  198. else { ?>
  199. <?php echo '<li class="no_related_post">' . __( 'No Related Posts Yet!', 'bonestheme' ) . '</li>'; ?>
  200. <?php }
  201. }
  202. wp_reset_postdata();
  203. echo '</ul>';
  204. } /* end bones related posts function */
  205. /*********************
  206. PAGE NAVI
  207. *********************/
  208. // Numeric Page Navi (built into the theme by default)
  209. function bones_page_navi() {
  210. global $wp_query;
  211. $bignum = 999999999;
  212. if ( $wp_query->max_num_pages <= 1 )
  213. return;
  214. echo '<nav class="pagination">';
  215. echo paginate_links( array(
  216. 'base' => str_replace( $bignum, '%#%', esc_url( get_pagenum_link($bignum) ) ),
  217. 'format' => '',
  218. 'current' => max( 1, get_query_var('paged') ),
  219. 'total' => $wp_query->max_num_pages,
  220. 'prev_text' => '&larr;',
  221. 'next_text' => '&rarr;',
  222. 'type' => 'list',
  223. 'end_size' => 3,
  224. 'mid_size' => 3
  225. ) );
  226. echo '</nav>';
  227. } /* end page navi */
  228. /*********************
  229. RANDOM CLEANUP ITEMS
  230. *********************/
  231. // remove the p from around imgs (http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/)
  232. function bones_filter_ptags_on_images($content){
  233. return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
  234. }
  235. // This removes the annoying […] to a Read More link
  236. function bones_excerpt_more($more) {
  237. global $post;
  238. // edit here if you like
  239. return '... <a class="excerpt-read-more" href="'. get_permalink($post->ID) . '" title="'. __( 'Read ', 'bonestheme' ) . get_the_title($post->ID).'">'. __( 'Read more &raquo;', 'bonestheme' ) .'</a>';
  240. }
  241. ?>