PageRenderTime 133ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/functions.php

https://bitbucket.org/illuxia/wordpress-custom-theme
PHP | 169 lines | 165 code | 4 blank | 0 comment | 22 complexity | cf78793ee115bfa3df9d688eeed21e16 MD5 | raw file
  1. <?php
  2. add_action( 'after_setup_theme', 'generic_setup' );
  3. function generic_setup() {
  4. load_theme_textdomain( 'generic', get_template_directory() . '/languages' );
  5. add_theme_support( 'title-tag' );
  6. add_theme_support( 'automatic-feed-links' );
  7. add_theme_support( 'post-thumbnails' );
  8. add_theme_support( 'html5', array( 'search-form' ) );
  9. global $content_width;
  10. if ( ! isset( $content_width ) ) { $content_width = 1920; }
  11. register_nav_menus( array( 'main-menu' => esc_html__( 'Main Menu', 'generic' ) ) );
  12. }
  13. add_action( 'wp_enqueue_scripts', 'generic_load_scripts' );
  14. function generic_load_scripts() {
  15. wp_enqueue_style( 'generic-style', get_stylesheet_uri() );
  16. wp_enqueue_script( 'jquery' );
  17. wp_register_script( 'generic-videos', get_template_directory_uri() . '/js/videos.js' );
  18. wp_enqueue_script( 'generic-videos' );
  19. wp_add_inline_script( 'generic-videos', 'jQuery(document).ready(function($){$("#wrapper").vids();});' );
  20. }
  21. add_action( 'wp_footer', 'generic_footer_scripts' );
  22. function generic_footer_scripts() {
  23. ?>
  24. <script>
  25. jQuery(document).ready(function ($) {
  26. var deviceAgent = navigator.userAgent.toLowerCase();
  27. if (deviceAgent.match(/(iphone|ipod|ipad)/)) {
  28. $("html").addClass("ios");
  29. $("html").addClass("mobile");
  30. }
  31. if (navigator.userAgent.search("MSIE") >= 0) {
  32. $("html").addClass("ie");
  33. }
  34. else if (navigator.userAgent.search("Chrome") >= 0) {
  35. $("html").addClass("chrome");
  36. }
  37. else if (navigator.userAgent.search("Firefox") >= 0) {
  38. $("html").addClass("firefox");
  39. }
  40. else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) {
  41. $("html").addClass("safari");
  42. }
  43. else if (navigator.userAgent.search("Opera") >= 0) {
  44. $("html").addClass("opera");
  45. }
  46. $(":checkbox").on("click", function () {
  47. $(this).parent().toggleClass("checked");
  48. });
  49. });
  50. </script>
  51. <?php
  52. }
  53. add_filter( 'document_title_separator', 'generic_document_title_separator' );
  54. function generic_document_title_separator( $sep ) {
  55. $sep = '|';
  56. return $sep;
  57. }
  58. add_filter( 'the_title', 'generic_title' );
  59. function generic_title( $title ) {
  60. if ( $title == '' ) {
  61. return '...';
  62. } else {
  63. return $title;
  64. }
  65. }
  66. add_filter( 'the_content_more_link', 'generic_read_more_link' );
  67. function generic_read_more_link() {
  68. if ( ! is_admin() ) {
  69. return ' <a href="' . esc_url( get_permalink() ) . '" class="more-link">...</a>';
  70. }
  71. }
  72. add_filter( 'excerpt_more', 'generic_excerpt_read_more_link' );
  73. function generic_excerpt_read_more_link( $more ) {
  74. if ( ! is_admin() ) {
  75. global $post;
  76. return ' <a href="' . esc_url( get_permalink( $post->ID ) ) . '" class="more-link">...</a>';
  77. }
  78. }
  79. add_filter( 'intermediate_image_sizes_advanced', 'generic_image_insert_override' );
  80. function generic_image_insert_override( $sizes ) {
  81. unset( $sizes['medium_large'] );
  82. return $sizes;
  83. }
  84. add_action( 'widgets_init', 'generic_widgets_init' );
  85. function generic_widgets_init() {
  86. register_sidebar( array(
  87. 'name' => esc_html__( 'Sidebar Widget Area', 'generic' ),
  88. 'id' => 'primary-widget-area',
  89. 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
  90. 'after_widget' => '</li>',
  91. 'before_title' => '<h3 class="widget-title">',
  92. 'after_title' => '</h3>',
  93. ) );
  94. }
  95. add_action( 'wp_head', 'generic_pingback_header' );
  96. function generic_pingback_header() {
  97. if ( is_singular() && pings_open() ) {
  98. printf( '<link rel="pingback" href="%s" />' . "\n", esc_url( get_bloginfo( 'pingback_url' ) ) );
  99. }
  100. }
  101. add_action( 'comment_form_before', 'generic_enqueue_comment_reply_script' );
  102. function generic_enqueue_comment_reply_script() {
  103. if ( get_option( 'thread_comments' ) ) {
  104. wp_enqueue_script( 'comment-reply' );
  105. }
  106. }
  107. function generic_custom_pings( $comment ) {
  108. ?>
  109. <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"><?php echo comment_author_link(); ?></li>
  110. <?php
  111. }
  112. add_filter( 'get_comments_number', 'generic_comment_count', 0 );
  113. function generic_comment_count( $count ) {
  114. if ( ! is_admin() ) {
  115. global $id;
  116. $get_comments = get_comments( 'status=approve&post_id=' . $id );
  117. $comments_by_type = separate_comments( $get_comments );
  118. return count( $comments_by_type['comment'] );
  119. } else {
  120. return $count;
  121. }
  122. }
  123. function slider_widget() {
  124. register_sidebar(array(
  125. 'name' => 'Slider-Widget',
  126. 'id' => 'widget-slider',
  127. 'before_widget' => '<div class="slider-widget">',
  128. 'after_widget' => '</div>',
  129. 'before_title' => '<h3 class="slider-widget-title">',
  130. 'after_title' => '</h3>',
  131. ));
  132. }
  133. add_action('widgets_init', 'slider_widget');
  134. function left_footer_widget() {
  135. register_sidebar(array(
  136. 'name' => 'Left Footer',
  137. 'id' => 'widget-footer-area-left',
  138. 'before_widget' => '<div class="left-footer">',
  139. 'after_widget' => '</div>',
  140. 'before_title' => '<h3 class="footer-widget-title">',
  141. 'after_title' => '</h3>',
  142. ));}
  143. add_action('widgets_init', 'left_footer_widget');
  144. function middle_footer_widget() {
  145. register_sidebar(array(
  146. 'name' => 'Middle Footer',
  147. 'id' => 'widget-footer-area-middle',
  148. 'before_widget' => '<div class="middle-footer">',
  149. 'after_widget' => '</div>',
  150. 'before_title' => '<h3 class="footer-widget-title">',
  151. 'after_title' => '</h3>',
  152. ));
  153. }
  154. add_action('widgets_init', 'middle_footer_widget');
  155. function right_footer_widget() {
  156. register_sidebar(array(
  157. 'name' => 'Right Footer',
  158. 'id' => 'widget-footer-area-right',
  159. 'before_widget' => '<div class="right-footer">',
  160. 'after_widget' => '</div>',
  161. 'before_title' => '<h3 class="footer-widget-title">',
  162. 'after_title' => '</h3>',
  163. ));
  164. }
  165. add_action('widgets_init', 'right_footer_widget');