/functions.php
PHP | 169 lines | 165 code | 4 blank | 0 comment | 22 complexity | cf78793ee115bfa3df9d688eeed21e16 MD5 | raw file
- <?php
- add_action( 'after_setup_theme', 'generic_setup' );
- function generic_setup() {
- load_theme_textdomain( 'generic', get_template_directory() . '/languages' );
- add_theme_support( 'title-tag' );
- add_theme_support( 'automatic-feed-links' );
- add_theme_support( 'post-thumbnails' );
- add_theme_support( 'html5', array( 'search-form' ) );
- global $content_width;
- if ( ! isset( $content_width ) ) { $content_width = 1920; }
- register_nav_menus( array( 'main-menu' => esc_html__( 'Main Menu', 'generic' ) ) );
- }
- add_action( 'wp_enqueue_scripts', 'generic_load_scripts' );
- function generic_load_scripts() {
- wp_enqueue_style( 'generic-style', get_stylesheet_uri() );
- wp_enqueue_script( 'jquery' );
- wp_register_script( 'generic-videos', get_template_directory_uri() . '/js/videos.js' );
- wp_enqueue_script( 'generic-videos' );
- wp_add_inline_script( 'generic-videos', 'jQuery(document).ready(function($){$("#wrapper").vids();});' );
- }
- add_action( 'wp_footer', 'generic_footer_scripts' );
- function generic_footer_scripts() {
- ?>
- <script>
- jQuery(document).ready(function ($) {
- var deviceAgent = navigator.userAgent.toLowerCase();
- if (deviceAgent.match(/(iphone|ipod|ipad)/)) {
- $("html").addClass("ios");
- $("html").addClass("mobile");
- }
- if (navigator.userAgent.search("MSIE") >= 0) {
- $("html").addClass("ie");
- }
- else if (navigator.userAgent.search("Chrome") >= 0) {
- $("html").addClass("chrome");
- }
- else if (navigator.userAgent.search("Firefox") >= 0) {
- $("html").addClass("firefox");
- }
- else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) {
- $("html").addClass("safari");
- }
- else if (navigator.userAgent.search("Opera") >= 0) {
- $("html").addClass("opera");
- }
- $(":checkbox").on("click", function () {
- $(this).parent().toggleClass("checked");
- });
- });
- </script>
- <?php
- }
- add_filter( 'document_title_separator', 'generic_document_title_separator' );
- function generic_document_title_separator( $sep ) {
- $sep = '|';
- return $sep;
- }
- add_filter( 'the_title', 'generic_title' );
- function generic_title( $title ) {
- if ( $title == '' ) {
- return '...';
- } else {
- return $title;
- }
- }
- add_filter( 'the_content_more_link', 'generic_read_more_link' );
- function generic_read_more_link() {
- if ( ! is_admin() ) {
- return ' <a href="' . esc_url( get_permalink() ) . '" class="more-link">...</a>';
- }
- }
- add_filter( 'excerpt_more', 'generic_excerpt_read_more_link' );
- function generic_excerpt_read_more_link( $more ) {
- if ( ! is_admin() ) {
- global $post;
- return ' <a href="' . esc_url( get_permalink( $post->ID ) ) . '" class="more-link">...</a>';
- }
- }
- add_filter( 'intermediate_image_sizes_advanced', 'generic_image_insert_override' );
- function generic_image_insert_override( $sizes ) {
- unset( $sizes['medium_large'] );
- return $sizes;
- }
- add_action( 'widgets_init', 'generic_widgets_init' );
- function generic_widgets_init() {
- register_sidebar( array(
- 'name' => esc_html__( 'Sidebar Widget Area', 'generic' ),
- 'id' => 'primary-widget-area',
- 'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
- 'after_widget' => '</li>',
- 'before_title' => '<h3 class="widget-title">',
- 'after_title' => '</h3>',
- ) );
- }
- add_action( 'wp_head', 'generic_pingback_header' );
- function generic_pingback_header() {
- if ( is_singular() && pings_open() ) {
- printf( '<link rel="pingback" href="%s" />' . "\n", esc_url( get_bloginfo( 'pingback_url' ) ) );
- }
- }
- add_action( 'comment_form_before', 'generic_enqueue_comment_reply_script' );
- function generic_enqueue_comment_reply_script() {
- if ( get_option( 'thread_comments' ) ) {
- wp_enqueue_script( 'comment-reply' );
- }
- }
- function generic_custom_pings( $comment ) {
- ?>
- <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"><?php echo comment_author_link(); ?></li>
- <?php
- }
- add_filter( 'get_comments_number', 'generic_comment_count', 0 );
- function generic_comment_count( $count ) {
- if ( ! is_admin() ) {
- global $id;
- $get_comments = get_comments( 'status=approve&post_id=' . $id );
- $comments_by_type = separate_comments( $get_comments );
- return count( $comments_by_type['comment'] );
- } else {
- return $count;
- }
- }
- function slider_widget() {
- register_sidebar(array(
- 'name' => 'Slider-Widget',
- 'id' => 'widget-slider',
- 'before_widget' => '<div class="slider-widget">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="slider-widget-title">',
- 'after_title' => '</h3>',
- ));
- }
- add_action('widgets_init', 'slider_widget');
- function left_footer_widget() {
- register_sidebar(array(
- 'name' => 'Left Footer',
- 'id' => 'widget-footer-area-left',
- 'before_widget' => '<div class="left-footer">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="footer-widget-title">',
- 'after_title' => '</h3>',
- ));}
- add_action('widgets_init', 'left_footer_widget');
- function middle_footer_widget() {
- register_sidebar(array(
- 'name' => 'Middle Footer',
- 'id' => 'widget-footer-area-middle',
- 'before_widget' => '<div class="middle-footer">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="footer-widget-title">',
- 'after_title' => '</h3>',
- ));
- }
- add_action('widgets_init', 'middle_footer_widget');
- function right_footer_widget() {
- register_sidebar(array(
- 'name' => 'Right Footer',
- 'id' => 'widget-footer-area-right',
- 'before_widget' => '<div class="right-footer">',
- 'after_widget' => '</div>',
- 'before_title' => '<h3 class="footer-widget-title">',
- 'after_title' => '</h3>',
- ));
- }
- add_action('widgets_init', 'right_footer_widget');