-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·190 lines (176 loc) · 7.45 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/*---------------------------------------------------------
* Constants
---------------------------------------------------------*/
$wp_theme = wp_get_theme();
// Theme Version
if ( ! defined( 'FCWP_VERSION' ) ) {
define( 'FCWP_VERSION', $wp_theme->get( 'Version' ) );
}
// Theme Prefix
if ( ! defined( 'FCWP_PREFIX' ) ) {
define( 'FCWP_PREFIX', 'dfw' );
}
// Theme Name
if ( !defined( 'FCWP_NAME' ) ) {
define( 'FCWP_NAME', $wp_theme->get( 'Name' ) );
}
// Theme URI
if ( !defined( 'FCWP_URI' ) ) {
define( 'FCWP_URI', esc_url( get_template_directory_uri() ) );
}
// Theme Stylesheet URI
if ( !defined( 'FCWP_STYLESHEETURI' ) ) {
define( 'FCWP_STYLESHEETURI', esc_url( get_stylesheet_uri() ) );
}
// Theme Directory
if ( !defined( 'FCWP_DIR' ) ) {
define( 'FCWP_DIR', get_template_directory() );
}
/*---------------------------------------------------------
* Theme Setup
---------------------------------------------------------*/
if( !function_exists( 'fcwp_theme_support' ) ) :
function fcwp_theme_support() {
// Load taxdomain
load_theme_textdomain( 'dfw', get_template_directory() . '/languages' );
// Title Tage Support
add_theme_support( 'title-tag' );
// Post Thumbnails
add_theme_support( 'post-thumbnails' );
add_image_size( 'monitor', 1400, 9999 );
add_image_size( 'tablet', 1024, 9999 );
add_image_size( 'mobile', 480, 9999 );
// Register Nav Menus*/
register_nav_menus( array(
'primary' => __( 'Primary', 'dfw' ),
) );
}
add_action( 'after_setup_theme', 'fcwp_theme_support' );
endif;
/*---------------------------------------------------------
* Remove Default Image Sizes
---------------------------------------------------------*/
if( !function_exists( 'fcwp_remove_default_image_sizes' ) ) :
function fcwp_remove_default_image_sizes( $sizes) {
unset( $sizes['medium']);
unset( $sizes['large']);
return $sizes;
}
add_filter( 'intermediate_image_sizes_advanced', 'fcwp_remove_default_image_sizes' );
add_filter('image_size_names_choose', 'fcwp_remove_default_image_sizes');
endif;
/*---------------------------------------------------------
* Custom Nav Walker
---------------------------------------------------------*/
if( !class_exists( 'fcwp_walker_nav_menu' ) ) :
class fcwp_walker_nav_menu extends Walker_Nav_Menu {
// add classes to ul sub-menus
public function start_lvl( &$output, $depth = 0, $args = array() ) {
// depth dependent classes
$indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' ); // code indent
$display_depth = ( $depth + 1); // because it counts the first submenu as 0
$classes = array(
'sub-menu',
'menu-depth-' . $display_depth
);
$class_names = implode( ' ', $classes );
// build html
$output .= "\n" . $indent . '<ul class="' . $class_names . '">' . "\n";
}
// add main/sub classes to li's and links
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$indent = ( $depth > 0 ? str_repeat( "\t", $depth ) : '' );
$display_depth = ( $depth + 1);
// depth dependent classes
$depth_classes = array(
( $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ),
'menu-item-depth-' . $depth,
'menu-item-' . strtolower( str_replace( ' ', '-', $item->title ) )
);
$depth_class_names = esc_attr( implode( ' ', $depth_classes ) );
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = esc_attr( implode( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ) );
// build html
$output .= $indent . '<li class="' . $depth_class_names . ' ' . $class_names . '" role="menuitem" aria-lable="' . apply_filters( 'the_title', $item->title, $item->ID ) . '">';
// link attributes
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$attributes .= ' class="menu-link ' . ( $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ) . '"';
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
// build html
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
endif;
/*---------------------------------------------------------
* Load Stylesheets
---------------------------------------------------------*/
if( !function_exists( 'fcwp_load_stylesheets' ) ) :
function fcwp_load_stylesheets() {
// Load the main stylesheet.
wp_enqueue_style( 'fcwp-style', FCWP_STYLESHEETURI, array(), '1.0.0', 'all' );
// Load the Internet Explorer 9 specific stylesheet.
wp_enqueue_style( 'fcwp-ie9-style', FCWP_URI . '/css/ie9.style.css', array( 'fcwp-style' ), '1.0.0' );
wp_style_add_data( 'fcwp-ie9-style', 'conditional', 'IE 9' );
wp_enqueue_style( 'fcwp-fonts', 'http://fast.fonts.net/cssapi/9805d080-c76c-4e5e-ac87-e51e5cada71d.css', array( 'fcwp-style' ), '1.0.0' );
}
add_action( 'wp_enqueue_scripts', 'fcwp_load_stylesheets' );
endif;
/*---------------------------------------------------------
* Load JavaScript
---------------------------------------------------------*/
if( !function_exists( 'fcwp_load_child_javascript' ) ) :
function fcwp_load_child_javascript() {
// jQuery
wp_enqueue_script('jquery');
// scripts.min.js
wp_register_script( 'scripts.min.js', FCWP_URI . '/js/scripts.min.js', array( 'jquery' ), '1.0.0', true );
wp_enqueue_script( 'scripts.min.js' );
}
add_action( 'wp_enqueue_scripts', 'fcwp_load_child_javascript' );
endif;
/*---------------------------------------------------------
* IE Conditional JavaScript
---------------------------------------------------------*/
if( !function_exists( 'fcwp_load_ie' ) ) :
function fcwp_load_ie() {
ob_start();?>
<!--[if (lt IE 9) & (!IEMobile)]><script src="<?php echo FCWP_STYLESHEETURI; ?>/js/ie.min.js"></script><![endif]-->
<?php
echo ob_get_clean();
}
add_action( 'wp_head', 'fcwp_load_ie',10 );
endif;
/*---------------------------------------------------------
* Sidebar Widget Area
---------------------------------------------------------*/
function fcwp_register_custom_sidebars() {
register_sidebar( array(
'name' => __( 'Sidebar', 'dfw' ),
'id' => 'sidebar',
'description' => '',
'class' => '',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>'
));
}
add_action( 'widgets_init', 'fcwp_register_custom_sidebars' );
/*---------------------------------------------------------
* Remove jQuery Migrate from Fronend
---------------------------------------------------------*/
add_filter( 'wp_default_scripts', 'remove_jquery_migrate' );
function remove_jquery_migrate( &$scripts ){
if( !is_admin() ){
$scripts->remove( 'jquery');
$scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );
}
}