bones.php 8.8 KB

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