bones.php 9.0 KB

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