lacee1986
8/9/2016 - 2:24 PM

Functions file

Functions file

<?php
/* Theme Support */
add_theme_support('post-thumbnails');

/* Advanced Custom Fields - Options Pages */
if( function_exists('acf_add_options_page') ) {
    acf_add_options_page(array(
        'page_title' 	=> 'Theme General Settings',
        'menu_title'	=> 'Theme Settings',
        'menu_slug' 	=> 'theme-general-settings',
        'capability'	=> 'edit_posts',
        'icon_url'              => 'dashicons-admin-tools',
        'redirect'	=> true
    ));
    acf_add_options_sub_page(array(
        'page_title' 	=> 'Homepage Settings',
        'menu_title'	=> 'Homepage',
        'parent_slug'	=> 'theme-general-settings',
    ));
    acf_add_options_sub_page(array(
        'page_title' 	=> 'Shop Settings',
        'menu_title'	=> 'Shop',
        'parent_slug'	=> 'theme-general-settings',
    ));
}

/* Hide admin bar */
add_filter('show_admin_bar', '__return_false');

/* Show Page Template */
add_action('wp_head', 'show_template');
function show_template() {
    global $template;
    $template = '<div id="page_template"><span>Template URL:</span> '.$template.'</div>';
    if ( is_super_admin() ) { print_r($template); }
}

/* Load Google Fonts - Optional */
add_action( 'wp_enqueue_scripts', 'custom_enqueue_google_font' );
function custom_enqueue_google_font() {
    $query_josefin = array('family' => 'Josefin+Sans:400,600,700');
    $query_cookie = array('family' => 'Cookie');
    wp_register_style( 'google-fonts-josefin', add_query_arg( $query_josefin, "//fonts.googleapis.com/css" ), array(), null );
    wp_register_style( 'google-fonts-cookie', add_query_arg( $query_cookie, "//fonts.googleapis.com/css" ), array(), null );
    wp_enqueue_style( 'google-fonts-josefin' );
    wp_enqueue_style( 'google-fonts-cookie' );
}

/* Load the theme stylesheets */
add_action('wp_enqueue_scripts', 'theme_styles');
function theme_styles() { 
    wp_enqueue_style( 'slick', get_template_directory_uri() . '/css/slick.css' ); // Slider stylesheet
    wp_enqueue_style( 'main', get_template_directory_uri() . '/css/main.css' ); // Main stylesheet 
    wp_enqueue_style( 'responsive', get_template_directory_uri() . '/css/responsive.css' ); // Responsive stylesheet 
}

/* Load the theme scripts */
// add_action('wp_enqueue_scripts', 'theme_scripts');
function theme_scripts() { 
    wp_register_script( 'jquery', get_template_directory_uri() . '/js/jquery.js' ); // Main jQuery file for production
    wp_register_script( 'jqueryvalidate', get_template_directory_uri() . '/js/jquery.validate.js' ); // Main jQuery file for production
    wp_register_script( 'gmapsapi', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyB5sEJjC0Abr5bPHv5-evXpWQTWvjyLGY4', array(), '1.0.0', false ); // Optional for Google Maps API
    wp_register_script( 'acfmap', get_template_directory_uri() . '/js/acfmap.js' ); // Main jQuery file for production
    wp_register_script( 'modernizer', get_template_directory_uri() . '/js/modernizr.js' ); // Main jQuery file for production
    wp_register_script( 'respond', get_template_directory_uri() . '/js/respond.js' ); // Main jQuery file for production
    wp_register_script( 'customselect', get_template_directory_uri() . '/js/jquery.customSelect.min.js' ); // Main jQuery file for production
    wp_register_script( 'slick', get_template_directory_uri() . '/js/slick.js' ); // Main jQuery file for production
    wp_register_script( 'ajax', get_template_directory_uri() . '/js/ajax.js' ); // Main jQuery file for production
    wp_register_script( 'main', get_template_directory_uri() . '/js/main.js' ); // Main jQuery file for production
    wp_enqueue_script('jquery');
    wp_enqueue_script('jqueryvalidate');
    wp_enqueue_script('gmapsapi');
    wp_enqueue_script('acfmap');
    wp_enqueue_script('modernizer');
    wp_enqueue_script('respond');
    wp_enqueue_script('customselect');
    wp_enqueue_script('slick');
    wp_enqueue_script('ajax');
    wp_enqueue_script('main');
}

/* Custom Login Page */
add_action("login_head", "my_login_head");
function my_login_head() {
     echo "<link rel='stylesheet' href='" . get_template_directory_uri() . "/functions/functions.css' />";
}

/* Custom Post Image Sizes */
add_image_size( 'home-product-thumb', 250, 250, true );

/* Menu - Registering */
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
  register_nav_menus(
    array(
      'main_menu' => __( 'Main Menu Place' )
    )
  );
}

/* Add Woocommerce support */
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
    add_theme_support( 'woocommerce' );
}

/* Create our own excerpt - in loop */
function get_content_short($maxchar) {
    $dots = $maxchar + 3;
    $content = get_the_content();
    $content = strip_tags($content);
    $content = (strlen($content) > $dots) ? substr($content,0,$maxchar).'...' : $content;
    return $content;
}

/* Breadcrumbs */
function the_breadcrumb() {
    global $post;
    echo '<ul id="breadcrumbs_list">';
    if (!is_home()) {
        echo '<li><a href="' . home_url() . '" title="Home">Home</a></li><li class="seperator">&nbsp;/&nbsp;</li>';
        // IF SINGLE
        if (is_single()) {
            if (is_singular('YOUR_POST_TYPE')) {
                echo '</li><li><a href="LINK" title="TITLE">TITLE</a></li>';
                echo '<li><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">' . get_the_title($post->ID) . '</a></li>';
            } elseif (is_singular('YOUR_POST_TYPE_2')) {
                echo '</li><li><a href="LINK" title="TITLE">TITLE</a></li>';
                echo '</li><li><a href="LINK" title="TITLE">TITLE</a></li>';
                echo '<li><a href="' . get_permalink($post->ID) . '" title="' . get_the_title($post->ID) . '">' . get_the_title($post->ID) . '</a></li>';
            }
        // IF CATEGORY
        } elseif (is_category()) {
            echo '<li>';
            the_category(' </li><li> ');
            if (is_single()) {
                echo '</li><li>';
                the_title();
                echo '</li>';
            }
        // IF PAGE
        } elseif (is_page()) {
            if ($post->post_parent) {
                $anc = array_reverse(get_post_ancestors($post->ID));
                $title = get_the_title();
                foreach ($anc as $ancestor) {
                    echo '<li><a href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li><li class="seperator">&nbsp;/&nbsp;</li>';
                }
                echo '<li><a class="current" href="' . get_permalink() . '" title="' . $title . '">' . $title . '</a></li>';
            } else {
                echo '<li><a class="current" href="' . get_permalink() . '" title="' . get_the_title() . '">' . get_the_title() . '</a></li>';
            }
        } elseif (is_archive()) {
            echo '</li><li><a href="LINK" title="TITLE">TITLE</a></li>';
            echo '<li>Archive</li>';
        }
    } elseif (is_tag()) {
        single_tag_title();
    } elseif (is_day()) {
        echo"<li>Archive for ";
        the_time('F jS, Y');
        echo'</li>';
    } elseif (is_month()) {
        echo"<li>Archive for ";
        the_time('F, Y');
        echo'</li>';
    } elseif (is_year()) {
        echo"<li>Archive for ";
        the_time('Y');
        echo'</li>';
    } elseif (is_author()) {
        echo"<li>Author Archive";
        echo'</li>';
    } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {
        echo "<li>Blog Archives";
        echo'</li>';
    } elseif (is_search()) {
        echo"<li>Search Results";
        echo'</li>';
    }
    echo '</ul>';
}

/* Shortcodes - Button */
add_shortcode( 'button', 'button_shortcode' );
function button_shortcode( $atts, $content = null ) {
    return '<div class="button_wrapper">' . $content . '</div>';
}

/* Shortcodes - Column */
add_shortcode('column', 'anpost_columns_shortcode');
function anpost_columns_shortcode($atts, $content = null) {
   extract(shortcode_atts(array('type' => '#'), $atts));
   $content = str_replace('</p><p>', '', $content);
   return '<div class="custom_column '. $type . '">' . do_shortcode($content) . '</div>';
}

?>