-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
248 lines (185 loc) · 6.63 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
/*
This function sets up the theme defaults and registers support for wordpress features that can
be hooked into the after_setup_theme hook
*/
function bukaba_setup() {
/* register nav menu in two locations */
register_nav_menus(
array(
'primary' => esc_html__('Primary', 'bukaba'),
'social-footer' => esc_html__('Social Links Footer', 'bukaba')
)
);
/*
This registers the header customisations including image and header text colour
*/
$header_info = array (
'default-image' => get_parent_theme_file_uri('/assets/images/grey.jpg'),
'default-text-color' => '000000',
'width' => 1000,
'height' => 250,
'flex-height' => true,
'flex-width' => true,
'wp-head-callback' => 'bukaba_header_style',
);
add_theme_support('custom-header', $header_info);
// set default header images
$header_images = array(
'grey' => array (
'url' => '%s/assets/images/grey.jpg',
'description' => __('Grey', 'bukaba'),
'thumbnail_url' => '%s/assets/images/grey.jpg',
),
'blue' => array (
'url' => '%s/assets/images/blue.jpg',
'description' => __('Blue', 'bukaba'),
'thumbnail_url' => '%s/assets/images/blue.jpg',
),
);
register_default_headers($header_images);
/*
This will register theme support for logos and customise the logo
*/
$defaults = array (
'height' => 100,
'width' => 100,
);
add_theme_support('custom-logo', $defaults);
/*
This will register theme support for post formats
*/
add_theme_support('post-formats', array('aside', 'quote', 'link', 'image'));
/*
This will register theme support for post thumbnails
*/
add_theme_support('post-thumbnails', array('post', 'image'));
/*
This will register theme support for html5
*/
add_theme_support('html5');
/*
This will register theme support for aautomatic feed links
*/
add_theme_support('automatic-feed-links');
/*
Registers theme support for WordPress Titles
*/
add_theme_support( 'title-tag' );
/* Set up the WordPress core custom background feature.
*/
add_theme_support( 'custom-background', apply_filters( 'bukaba_custom_background_args', array(
'default-color' => '#FFFFF0',
'default-image' => '',
) ) );
/* set the content width */
function bukaba_content_width() {
$GLOBALS['content_width'] = apply_filters( 'bukaba_content_width', 640 );
}
} //end of theme setup function
add_action( 'after_setup_theme', 'bukaba_setup' );
//function to add styling for the header text colour
if (! function_exists('bukaba_header_style')):
function bukaba_header_style() {
$text_colour = get_header_textcolor();
if(get_theme_support( 'custom-header', 'default-text-color' ) === $text_colour) {
return;
}
else {
?>
<style id="-custom-header-styles" type="text/css">
.site-title a, .site-description {
color:#<?php echo esc_attr($text_colour); ?>;
}
.down .fa {
color:#<?php echo esc_attr($text_colour); ?>;
}
</style>
<?php
}
} //end function
endif; // End of header styling
/*
This is to create a single page template for the home page. When a new page is created it is added to the single page template for the home page and displayed using the given page template. Here the home page is created, the other pages are called in single-page-home.php
*/
if(get_page_by_title("Home") == null) {
$post = array(
"post_title" => "Home",
"post_status" => "publish",
"post_type" => "page",
"menu_order" => "-100",
"page_template" => "single-page-home.php"
);
wp_insert_post($post);
$home_page = get_page_by_title("Home");
update_option("page_on_front", $home_page->ID);
update_option("show_on_front", "page");
}
/*
Function to link the main menu items to the internal parts of the single page home page - the link for the post should not take the user to another page but the page location on the single page homepage.
Preconditions for this function are
1. Front page is a static front page
2. Home page template is the single-page-home.php page
3 The menu location is 'primary' so no other navs are affected
function bukaba_main_nav_menu_reroute($items, $args) {
if(get_option('show_on_front') == 'page' && get_page_by_title("Home")->page_template =="single-page-home.php" && $args->theme_location == 'primary') {
$items="";
$filters = array ("post_type" => "page", "order" => "ASC", "orderby" => "menu_order");
$the_query = new WP_Query($filters);
if($the_query->have_posts()):
while($the_query->have_posts()):
$the_query->the_post();
$items .= '<li class="menu-item"><a href="#' .get_the_title() . '">' . get_the_title() . '</a></li>';
endwhile;
endif;
return $items;
} else {
return $items;
}
}
add_filter("wp_nav_menu_items", "bukaba_main_nav_menu_reroute", 10, 2);
*/
/**
**add custom scripts
**custom.js for all additional javascript
*/
function bukaba_add_custom_scripts() {
wp_register_script('custom_script', home_url() . '/wp-content/themes/bukaba/assets/js/custom.js', array( 'jquery' ));
wp_enqueue_script('custom_script');
}
add_action( 'wp_enqueue_scripts', 'bukaba_add_custom_scripts' );
/* Add comment-reply script */
function bukaba_queue_comments_reply(){
if ( (!is_admin()) && is_singular() && comments_open() && get_option('thread_comments') )
wp_enqueue_script( 'comment-reply' );
}
add_action('wp_print_scripts', 'bukaba_queue_comments_reply');
/**
**add custom google font styles and boostrap styles
*/
function bukaba_styles() {
wp_enqueue_style( 'bootstrap', get_template_directory_uri() .'/assets/css/bootstrap.min.css', array(), false ,'screen' );
wp_enqueue_style('custom-google-fonts','https://fonts.googleapis.com/css?family=Ubuntu:300,300i,400,400i,500,500i,700,700i', false);
wp_enqueue_style( 'custom-styles', get_template_directory_uri() .'/style.css');
wp_enqueue_style( 'load-fa', get_template_directory_uri() .'/assets/css/font-awesome-4.7.0/css/font-awesome.min.css');
}
add_action('wp_enqueue_scripts', 'bukaba_styles' );
/**
**add TinyMCE customisations
*/
function bukaba_custom_editor_styles() {
add_editor_style('assets/css/custom-editor-style.css');
}
add_action('admin_init', 'bukaba_custom_editor_styles');
/**
* Customizer additions.
*/
require get_parent_theme_file_path( '/inc/customizer.php' );
/**
* Include template file which creates a custom walker class for the social media menu
*/
require get_parent_theme_file_path( '/inc/social-menu.php' );
/**
* Include sidebar widget
*/
require get_parent_theme_file_path( '/inc/sidebar-widget.php' );