bones.php 8.2 KB

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