'FFF', 'default-image' => get_template_directory_uri() . '/img/bg.jpg' ));*/ // Add Support for Custom Header - Uncomment below if you're going to use /*add_theme_support('custom-header', array( 'default-image' => get_template_directory_uri() . '/img/headers/default.jpg', 'header-text' => false, 'default-text-color' => '000', 'width' => 1000, 'height' => 198, 'random-default' => false, 'wp-head-callback' => $wphead_cb, 'admin-head-callback' => $adminhead_cb, 'admin-preview-callback' => $adminpreview_cb ));*/ // Enables post and comment RSS feed links to head add_theme_support('automatic-feed-links'); // Localisation Support load_theme_textdomain('html5blank', get_template_directory() . '/languages'); } /*------------------------------------*\ Functions \*------------------------------------*/ // Load HTML5 Blank scripts (header.php) function html5blank_header_scripts() { if ($GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) { wp_register_script('conditionizr', get_template_directory_uri() . '/js/lib/conditionizr-4.3.0.min.js', array(), '4.3.0'); // Conditionizr wp_enqueue_script('conditionizr'); // Enqueue it! wp_register_script('modernizr', get_template_directory_uri() . '/js/lib/modernizr-2.7.1.min.js', array(), '2.7.1'); // Modernizr wp_enqueue_script('modernizr'); // Enqueue it! } wp_register_script('eq-height', get_template_directory_uri() . '/js/eq.js', array('jquery'), '1.0.0'); wp_enqueue_script('eq-height'); // Enqueue it! } function html5blank_custom_script() { if ($GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) { wp_register_script('erin_custom', get_template_directory_uri() . '/js/scripts.js', array('jquery'), '1.0.0'); // Custom scripts wp_enqueue_script('erin_custom'); // Enqueue it! } } // Load HTML5 Blank conditional scripts function html5blank_conditional_scripts() { if( is_page_template('template-frontpage.php') || is_page_template('template-our_culture.php') ) { wp_register_script('flexslider-js', get_template_directory_uri() . '/js/jquery.flexslider-min.js', array('jquery'), '2.5.0'); wp_enqueue_script('flexslider-js'); // Enqueue it! wp_register_style('flexslider-css', get_template_directory_uri() . '/css/flexslider.css', array(), '2.5.0', 'all'); wp_enqueue_style('flexslider-css'); // Enqueue it! } if( is_page_template('template-clients.php') ) { wp_register_script('isotope-js', get_template_directory_uri() . '/js/isotope.pkgd.min.js', array('jquery'), '2.2.2'); wp_enqueue_script('isotope-js'); // Enqueue it! } if( is_page_template('template-clients.php') || is_page_template('template-our_culture.php') || is_page(13) ) { wp_register_script('fancybox-js', get_template_directory_uri() . '/js/jquery.fancybox.pack.js', array('jquery'), '2.1.5'); wp_enqueue_script('fancybox-js'); // Enqueue it! wp_register_style('fancybox-css', get_template_directory_uri() . '/css/jquery.fancybox.css', array(), '2.5.0', 'all'); wp_enqueue_style('fancybox-css'); // Enqueue it! } if( is_page(5) ) { wp_register_script('mlens-js', get_template_directory_uri() . '/js/jquery.mlens-1.5.min.js', array('jquery'), '1.5'); wp_enqueue_script('mlens-js'); // Enqueue it! } } // Load HTML5 Blank styles function html5blank_styles() { wp_register_style('fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', '4.4.0', 'all'); wp_enqueue_style('fontawesome'); // Enqueue it! wp_register_style('normalize', get_template_directory_uri() . '/normalize.css', array(), '1.0', 'all'); wp_enqueue_style('normalize'); // Enqueue it! wp_register_style('html5blank', get_template_directory_uri() . '/style.css', array(), '1.0', 'all'); wp_enqueue_style('html5blank'); // Enqueue it! } // Register HTML5 Blank Navigation function register_html5_menu() { register_nav_menus(array( // Using array to specify more menus if needed 'header-menu' => __('Header Menu', 'html5blank'), // Main Navigation 'footer-menu' => __('Footer Menu', 'html5blank'), // Sidebar Navigation 'upper-menu' => __('Upper Right Menu', 'html5blank') // Upper Right Navigation )); } // Remove the
surrounding the dynamic navigation to cleanup markup function my_wp_nav_menu_args($args = '') { $args['container'] = false; return $args; } // Remove Injected classes, ID's and Page ID's from Navigation
  • items function my_css_attributes_filter($var) { return is_array($var) ? array() : ''; } // Remove invalid rel attribute values in the categorylist function remove_category_rel_from_category_list($thelist) { return str_replace('rel="category tag"', 'rel="tag"', $thelist); } // Add page slug to body class, love this - Credit: Starkers Wordpress Theme function add_slug_to_body_class($classes) { global $post; if (is_home()) { $key = array_search('blog', $classes); if ($key > -1) { unset($classes[$key]); } } elseif (is_page()) { $classes[] = sanitize_html_class($post->post_name); } elseif (is_singular()) { $classes[] = sanitize_html_class($post->post_name); } return $classes; } // If Dynamic Sidebar Exists if (function_exists('register_sidebar')) { // No widgets for this theme } // Remove wp_head() injected Recent Comment styles function my_remove_recent_comments_style() { global $wp_widget_factory; remove_action('wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' )); } // Remove comments on media function filter_media_comment_status( $open, $post_id ) { $post = get_post( $post_id ); if( $post->post_type == 'attachment' ) { return false; } return $open; } add_filter( 'comments_open', 'filter_media_comment_status', 10 , 2 ); // Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin function html5wp_pagination() { global $wp_query; $big = 999999999; echo paginate_links(array( 'base' => str_replace($big, '%#%', get_pagenum_link($big)), 'format' => '?paged=%#%', 'current' => max(1, get_query_var('paged')), 'total' => $wp_query->max_num_pages )); } // Custom Excerpts function short_excerpt($length) // Create 15 Word Callback for Index page Excerpts, call using html5wp_excerpt('short_excerpt'); { return 15; } function html5wp_index($length) // Create 25 Word Callback for Index page Excerpts, call using html5wp_excerpt('html5wp_index'); { return 25; } // Create 40 Word Callback for Custom Post Excerpts, call using html5wp_excerpt('html5wp_custom_post'); function html5wp_custom_post($length) { return 40; } // Create 60 Word Callback for Custom Post Excerpts, call using html5wp_excerpt('long_excerpt'); function long_excerpt($length) { return 60; } // Create the Custom Excerpts callback function html5wp_excerpt($length_callback = '', $more_callback = '') { global $post; if (function_exists($length_callback)) { add_filter('excerpt_length', $length_callback); } if (function_exists($more_callback)) { add_filter('excerpt_more', $more_callback); } $output = get_the_excerpt(); $output = apply_filters('wptexturize', $output); $output = apply_filters('convert_chars', $output); $output = '

    ' . $output . '

    '; echo $output; } // Custom View Article link to Post function html5_blank_view_article($more) { global $post; return '...
    ' . __('Read more >', 'html5blank') . ''; } // Remove Admin bar function remove_admin_bar() { return true; } // Remove Categories and Tags from Posts by hiding them // Remove from the menu add_action('admin_menu', 'my_remove_sub_menus'); function my_remove_sub_menus() { remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=category'); remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=post_tag'); } // Remove meta boxes on Edit Posts add_action('admin_menu','remove_my_post_metaboxes'); function remove_my_post_metaboxes() { remove_meta_box( 'categorydiv','post','normal' ); // Categories Metabox remove_meta_box( 'tagsdiv-post_tag','post','normal' ); // Tags Metabox } function my_manage_columns( $columns ) { unset($columns['categories'], $columns['tags']); return $columns; } function my_column_init() { add_filter( 'manage_posts_columns' , 'my_manage_columns' ); } add_action( 'admin_init' , 'my_column_init' ); // Remove 'text/css' from our enqueued stylesheet function html5_style_remove($tag) { return preg_replace('~\s+type=["\'][^"\']++["\']~', '', $tag); } // Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail function remove_thumbnail_dimensions( $html ) { $html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html); return $html; } // Custom Gravatar in Settings > Discussion function html5blankgravatar ($avatar_defaults) { $myavatar = get_template_directory_uri() . '/img/gravatar.jpg'; $avatar_defaults[$myavatar] = "Custom Gravatar"; return $avatar_defaults; } // Threaded Comments function enable_threaded_comments() { if (!is_admin()) { if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) { wp_enqueue_script('comment-reply'); } } } // Custom Comments Callback function html5blankcomments($comment, $args, $depth) { $GLOBALS['comment'] = $comment; extract($args, EXTR_SKIP); if ( 'div' == $args['style'] ) { $tag = 'div'; $add_below = 'comment'; } else { $tag = 'li'; $add_below = 'div-comment'; } ?> < id="comment-">
    %s says:'), get_comment_author_link()) ?>
    comment_approved == '0') : ?>
    $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
    Discussion add_filter('body_class', 'add_slug_to_body_class'); // Add slug to body class (Starkers build) add_filter('widget_text', 'do_shortcode'); // Allow shortcodes in Dynamic Sidebar add_filter('widget_text', 'shortcode_unautop'); // Remove

    tags in Dynamic Sidebars (better!) add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args'); // Remove surrounding

    from WP Navigation // add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation
  • injected classes (Commented out by default) // add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1); // Remove Navigation
  • injected ID (Commented out by default) // add_filter('page_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation
  • Page ID's (Commented out by default) add_filter('the_category', 'remove_category_rel_from_category_list'); // Remove invalid rel attribute add_filter('the_excerpt', 'shortcode_unautop'); // Remove auto

    tags in Excerpt (Manual Excerpts only) add_filter('the_excerpt', 'do_shortcode'); // Allows Shortcodes to be executed in Excerpt (Manual Excerpts only) add_filter('excerpt_more', 'html5_blank_view_article'); // Add 'View Article' button instead of [...] for Excerpts // add_filter('show_admin_bar', 'remove_admin_bar'); // Remove Admin bar add_filter('style_loader_tag', 'html5_style_remove'); // Remove 'text/css' from enqueued stylesheet add_filter('post_thumbnail_html', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to thumbnails add_filter('image_send_to_editor', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to post images // Remove Filters remove_filter('the_excerpt', 'wpautop'); // Remove

    tags from Excerpt altogether // Shortcodes add_shortcode( 'row', 'row_shortcode' ); add_shortcode( 'column', 'column_shortcode' ); /*------------------------------------*\ ShortCode Functions \*------------------------------------*/ // Add Row Shortcode function row_shortcode( $attr , $content = null ) { // Attributes $attr = shortcode_atts( array( 'class' => '', ), $attr ); return '

    ' . do_shortcode($content) . '
    '; } // [row class="foo"][/row] // Add Column Shortcode function column_shortcode( $attr , $content = null ) { // Attributes $attr = shortcode_atts( array( 'grid' => '', 'class' => '', 'position' => '', ), $attr ); // Code return '
    ' . ' ' . do_shortcode($content) . '
    '; } // [column grid="one-fourth" class="foo" position="first"][/column] // include MailChimp add_action('acf/save_post', 'my_save_post'); function my_save_post( $post_id ) { // bail early if not a contact_form post if( get_post_type($post_id) !== 'message' ) { return; } // bail early if editing in admin if( is_admin() ) { return; } // vars $post = get_post( $post_id ); // get custom fields (field group exists for content_form) $name = get_field('first_name', $post_id) . " " . get_field('last_name', $post_id); $email = get_field('email', $post_id); $mailing_list = get_field('mailing_list', $post_id); // email data $to = get_field('subject', $post_id); // email is in the value of the select $headers = 'From: ' . $name . ' <' . $email . '>' . "\r\n"; $field = get_field_object('subject'); $value = get_field('subject'); $subject_line = $field['choices'][ $value ]; $subject = $name . " " . $email . " - " . $subject_line; $body = get_field('message_content','options'); $body = str_replace("{{first_name}}", get_field('first_name', $post_id), $body); $body = str_replace("{{last_name}}", get_field('last_name', $post_id), $body); $body = str_replace("{{title}}", get_field('title', $post_id), $body); $body = str_replace("{{organization}}", get_field('organization', $post_id), $body); $body = str_replace("{{email}}", get_field('email', $post_id), $body); $body = str_replace("{{telephone}}", get_field('telephone', $post_id), $body); $body = str_replace(" {{attached_file_url}}", get_field('file', $post_id), $body); // Update post 37 $my_post = array( 'ID' => $post_id, 'post_title' => $subject ); // Update the post into the database wp_update_post( $my_post ); if($mailing_list){ $data = [ 'email' => $email, 'status' => 'subscribed', 'firstname' => get_field('first_name', $post_id), 'lastname' => get_field('last_name', $post_id) ]; syncMailchimp($data); } // send email wp_mail($to, $subject, $body, $headers ); } function syncMailchimp($data) { $apiKey = 'cb0eb65d0f5f94da34c683e7f96829ed-us10'; $listId = 'b1bf9cc021'; $memberId = md5(strtolower($data['email'])); $dataCenter = substr($apiKey,strpos($apiKey,'-')+1); $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId; $json = json_encode([ 'email_address' => $data['email'], 'status' => $data['status'], // "subscribed","unsubscribed","cleaned","pending" 'merge_fields' => [ 'FNAME' => $data['firstname'], 'LNAME' => $data['lastname'] ] ]); $ch = curl_init($url); curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $httpCode; }