'Main Menu', 'secondary' => 'Footer Menu', 'extra' => 'Extra Menu' ) ); function add_menu_link_class( $atts, $item, $args ) { if (property_exists($args, 'link_class')) { $atts['class'] = $args->link_class; } return $atts; } add_filter( 'nav_menu_link_attributes', 'add_menu_link_class', 1, 3 ); class kit_custom_main_menu extends Walker_Nav_Menu { # Menu start, equivalent to ' . "\n"; } } # Menu element, equivalent to
  • function start_el(&$output, $item, $depth = 0, $args=array(), $id = 0) { $object = $item->object; $type = $item->type; $title = $item->title; $description = $item->description; $permalink = $item->url; $theme_template_path = get_template_directory_uri(); if ($depth == 1) { $output .= '
  • "; $output .= ' '; $output .= $title; $output .= ' '; } else { $output .= "
  • "; $output .= ''; $output .= $title; $output .= ''; } } function end_el(&$output, $item, $depth = 0, $args=array(), $id = 0) { $object = $item->object; $type = $item->type; $title = $item->title; $description = $item->description; $permalink = $item->url; if ($depth == 1) { $output .= ' '; } else { $output .= '
  • '; } } } # Custom size settings for customizer function theme_customize_register( $wp_customize ) { $wp_customize->add_setting( 'theme_color', array( 'default' => '#009982', 'transport' => 'refresh', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'theme_color', array( 'section' => 'colors', 'label' => esc_html__( 'Theme color', 'theme' ), ) ) ); $wp_customize->add_setting( 'kit_sidenav-mail', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options' ), ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'sidenav_mail_control', array( 'label' => __( 'Contact mail', 'kit' ), 'description' => __( 'Mail address used in sidebar menu', 'kit' ), 'settings' => 'kit_sidenav-mail', 'priority' => 10, 'section' => 'title_tagline', 'type' => 'text', ) ) ); $wp_customize->add_setting( 'kit_sidenav-faqpage', array( 'sanitize_callback' => 'absint', 'default' => '' ), ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'kit_sidenav-faqpage', array( 'label' => __( 'FAQ page', 'kit' ), 'description' => __( 'FAQ page used in sidebar menu', 'kit' ), 'settings' => 'kit_sidenav-faqpage', 'section' => 'title_tagline', 'type' => 'dropdown-pages', ) ) ); $wp_customize->add_setting( 'kit_copyrighttext', array( 'default' => '', 'type' => 'option', 'capability' => 'edit_theme_options' ), ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'sidenav_copyrighttext', array( 'label' => __( 'Copyright text', 'kit' ), 'description' => __( 'Displayed in the footer', 'kit' ), 'settings' => 'kit_copyrighttext', 'section' => 'title_tagline', 'type' => 'text', ) ) ); $wp_customize->add_setting( 'kit_defaultimage' ); $wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'kit_defaultimage', array( 'label' => __( 'Default featured image', 'kit' ), 'settings' => 'kit_defaultimage', 'section' => 'title_tagline', ) ) ); } add_action( 'customize_register', 'theme_customize_register' ); # Apply custom CSS settings function hex2rgba($color, $opacity = false) { $default = 'rgb(0,0,0)'; //Return default if no color provided if(empty($color)) return $default; //Sanitize $color if "#" is provided if ($color[0] == '#' ) { $color = substr( $color, 1 ); } //Check if color has 6 or 3 characters and get values if (strlen($color) == 6) { $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); } elseif ( strlen( $color ) == 3 ) { $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); } else { return $default; } //Convert hexadec to rgb $rgb = array_map('hexdec', $hex); //Check if opacity is set(rgba or rgb) if($opacity){ if(abs($opacity) > 1) $opacity = 1.0; $output = 'rgba('.implode(",",$rgb).','.$opacity.')'; } else { $output = 'rgb('.implode(",",$rgb).')'; } //Return rgb(a) color string return $output; } function kit_customize_css() { $theme_color = get_theme_mod('theme_color', '#009982'); ?> is_search() ) { $query->set( 'posts_per_page', '10' ); } else { $query->set( 'posts_per_page', '9' ); } } add_action( 'pre_get_posts', 'kit_modify_posts_per_page' ); # Register widget area function kit_widgets_init() { register_sidebar( array( 'name' => 'Custom Footer Widget Area', 'id' => 'custom-footer-widget', 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '

    ', 'after_title' => '

    ', ) ); } add_action( 'widgets_init', 'kit_widgets_init' ); # Highlight query in search results function generate_excerpt($text, $query, $length) { $words = explode(' ', $text); $total_words = count($words); if ($total_words > $length) { $queryLow = array_map('strtolower', $query); $wordsLow = array_map('strtolower', $words); for ($i=0; $i <= $total_words; $i++) { foreach ($queryLow as $queryItem) { if (preg_match("/\b$queryItem\b/", $wordsLow[$i])) { $posFound = $i; break; } } if ($posFound) { break; } } if ($i > ($length+($length/2))) { $i = $i - ($length/2); } else { $i = 0; } } $cutword = array_splice($words,$i,$length); $excerpt = implode(' ', $cutword); $keys = implode('|', $query); $excerpt = preg_replace('/(' . $keys .')/iu', '\0', $excerpt); $excerptRet = '

    '; if ($i !== 0) { $excerptRet .= '... '; } $excerptRet .= $excerpt . ' ...

    '; return $excerptRet; } function search_excerpt_highlight() { $length = 32; $text = wp_strip_all_tags( get_the_content() ); $query = explode(' ', get_search_query()); print_r($query); echo generate_excerpt($text, $query, $length); }