-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
363 lines (303 loc) · 10.6 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<?php
// include Navbar Walker For customize bootsrtap Navigation
require_once get_template_directory() . '/bootstrap-navwalker.php';
// REMOVE GENERATOR META TAG
remove_action('wp_head', 'wp_generator');
// add featured images support
add_theme_support('post-thumbnails');
set_post_thumbnail_size( 300, 300 );
/** Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Function to add My Custom Styles
function tulip_add_styles(){
// bootstrap
wp_enqueue_style('bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css');
// custom admin
wp_enqueue_style('custom-admin-css', get_template_directory_uri() . '/css/custom-admin.css');
// Font Awesome
wp_enqueue_style('font-awesome-css', get_template_directory_uri() . '/css/font-awesome.min.css');
// include Parts of Pages Stylesheets
// Header
wp_enqueue_style('Header-css', get_template_directory_uri() . '/css/inc/header.css');
// Nav Bar in header
wp_enqueue_style('Navbar-css', get_template_directory_uri() . '/css/inc/navbar.css');
// Author Page
wp_enqueue_style('author-css', get_template_directory_uri() . '/css/inc/author.css');
// single page post
wp_enqueue_style('single-post-css', get_template_directory_uri() . '/css/inc/single-post.css');
// Footer
wp_enqueue_style('Footer-css', get_template_directory_uri() . '/css/inc/footer.css');
// The Custom Frame-Work For Theme
wp_enqueue_style('custom-frame-work-css', get_template_directory_uri() . '/css/custom-frame-work.css');
// Resposive File ' media '
wp_enqueue_style('media-css', get_template_directory_uri() . '/css/media.css');
// The Main Theme Style Hold INDEX.PHP
wp_enqueue_style('main-css', get_template_directory_uri() . '/css/main.css');
}
// Add Animate CSS
function animate_css_style() {
wp_register_style( 'animate-css',
get_template_directory_uri() . '/css/animate.min.css',
array(),
'20120725',
'screen' );
wp_enqueue_style( 'animate-css' );
}
add_action('wp_enqueue_scripts', 'animate_css_style');
// Add My Custom Scripts
function tulip_add_scripts(){
wp_enqueue_script('bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), false, true);
}
add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
wp_enqueue_script(
'your-script', // name your script so that you can attach other scripts and de-register, etc.
get_template_directory_uri() . '/js/main.js', // this is the location of your script file
array('jquery') // this array lists the scripts upon which your script depends
);
}
// Add Custom Menu Support == have Add Action down
function tulip_register_custom_menu() {
register_nav_menus(array(
'bootsrtap-menu' => 'Header Menu',
'footer-menu' => 'Footer Menu'
));
}
// Add the menu inside Function for call it in header
function tulip_header_navwp_nav_menu(){
wp_nav_menu(array(
'menu_id' => 'primary-menu',
'theme_location' => 'bootsrtap-menu',
'menu_class' => 'nav navbar-nav navbar-right animated wobble',
'container' => false,
'depth' =>3,
'walker' => new wp_bootstrap_navwalker(),
'fallback_cb' => 'Bootstrap_NavWalker::fallback', // For menu fallback
));
}
// Customize The Excerpt Words Length & Read More Dots
// added By @Emad
function tulip_extend_excerpt_length($length)
{
return 15;
}
function tulip_excerpt_change_dots($more)
{
return ' ...';
}
// Added by @Emad
// Filters
add_filter('excerpt_length', 'tulip_extend_excerpt_length');
add_filter('excerpt_more', 'tulip_excerpt_change_dots');
// Added by @Emad
// Action for add tulip Style files
add_action('wp_enqueue_scripts','tulip_add_styles');
// Action for add tulip Script files
add_action('wp_enqueue_scripts','tulip_add_scripts');
// Action for Add Tulip Custom menu
add_action('after_setup_theme', 'tulip_register_custom_menu');
function theme_prefix_the_custom_logo() {
if ( function_exists( 'the_custom_logo' ) ) {
the_custom_logo();
}
}
add_filter('get_custom_logo','change_logo_class');
function change_logo_class($html)
{
$html = str_replace('custom-logo-link', 'navbar-brand', $html);
return $html;
}
add_theme_support( 'custom-logo' );
// determine the excerpt length or number of words by filter
function tulip_custom_excerpt_length( $length ) {
if (is_author()){
return 100;
}else if(is_category()){
return 20;
}
else{
return 25;
}
}
add_filter( 'excerpt_length', 'tulip_custom_excerpt_length', 999 );
// Register 4 widgets Area in footer
function tulip_widgets_init() {
// First footer widget area, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'First Footer Widget Area', 'tulip' ),
'id' => 'first-footer-widget-area',
'description' => __( 'The first footer widget area', 'tulip' ),
'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Second Footer Widget Area, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'Second Footer Widget Area', 'tulip' ),
'id' => 'second-footer-widget-area',
'description' => __( 'The second footer widget area', 'tulip' ),
'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Third Footer Widget Area, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'Third Footer Widget Area', 'tulip' ),
'id' => 'third-footer-widget-area',
'description' => __( 'The third footer widget area', 'tulip' ),
'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
// Fourth Footer Widget Area, located in the footer. Empty by default.
register_sidebar( array(
'name' => __( 'Fourth Footer Widget Area', 'tulip' ),
'id' => 'fourth-footer-widget-area',
'description' => __( 'The fourth footer widget area', 'tulip' ),
'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
// Register sidebars by running tulip_widgets_init() on the widgets_init hook.
add_action( 'widgets_init', 'tulip_widgets_init' );
// Create Prev 1.2.3.4 Next
function numbering_pagination() {
global $wp_query; // Make WP_Query Global
$all_pages = $wp_query->max_num_pages;
$current_page = max(1, get_query_var('paged')); // Get All Posts
if ($all_pages > 1) { // check if Total Pages
return paginate_links(array(
'base' => get_pagenum_link() . '%_%',
'format' => 'page/%#%',
'current' => $current_page,
'mid_size' => 2,
'end_size' =>2
));
}
}
// Register Sidebars
function tulip_main_sidebar() {
$args = array(
'id' => 'sidebar-1',
'class' => 'sidebar-1',
'name' => __( 'Tulip Sidebar', 'text_domain' ),
'description' => __( 'Drop Your Widgets Here', 'text_domain' ),
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
);
register_sidebar( $args );
}
add_action( 'widgets_init', 'tulip_main_sidebar' );
// remove Paragraph from the post conten
function tulip_remove_p($content) {
remove_filter('the_conten', 'wpautop');
return $content;
}
add_filter('the_content', 'tulip_remove_p', 0);
// Removes a class from the body_class array.
add_filter('body_class', function (array $classes) {
if (in_array('rtl', $classes)) {
unset( $classes[array_search('rtl', $classes)] );
}
return $classes;
});
// Add specific CSS class by filter in body class
add_filter(
'body_class',
function($classes){
return array_merge($classes,array('index-page'));
}
);
// Most Commented posts
/**
* Display top commented posts.
*
* @package saidelbakkali.com
*
* @author Said El Bakkali
*/
if ( ! function_exists( 'sb_top_commented_posts' ) ) {
/**
* Display most commented posts en the Front-End.
*/
function sb_top_commented_posts() {
$sb_top_commented_posts = get_transient( 'sb_top_commented_posts_cache' );
if ( false === $sb_top_commented_posts ) {
// WP_Query arguments.
$args = array(
'post_status' => array( 'publish' ),
'posts_per_page' => '5' + count( get_option( 'sticky_posts' ) ),
'orderby' => 'comment_count',
);
// The Query.
$sb_top_commented_posts = new WP_Query( $args );
set_transient( 'sb_top_commented_posts_cache', $sb_top_commented_posts, DAY_IN_SECONDS );
}
// The Loop.
if ( ! is_wp_error( $sb_top_commented_posts ) && $sb_top_commented_posts->have_posts() ) {
// Start output buffering.
ob_start();
echo '<ul class="sb-top-commented-posts">';
while ( $sb_top_commented_posts->have_posts() ) {
$sb_top_commented_posts->the_post();
echo '<li>';
echo '<figure class="sb-top-commented-posts-thumbnail">';
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'sb-top-commented-posts' );
}
echo '</figure>';
echo '<div class="content">';
the_title( '<h3 class="sb-top-commented-posts-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h3>' );
comments_popup_link(
__( 'No comments yet', 'text-domain' ),
__( '1 comment', 'text-domain ' ),
__( '% comments', 'text-domain' ),
'comments-link sb-top-commented-posts-comments-link',
__( 'Comments are off for this post', 'text-domain' )
);
echo '</div></li>';
}
echo '</ul>';
$output = ob_get_clean();
// Return output.
return $output;
}// End if().
// Restore original Post Data.
wp_reset_postdata();
}
}// End if().
/**
* Delete transient from wp_options when comment count has been updated.
*/
function invalidate_sb_top_commented_posts_cache() {
delete_transient( 'sb_top_commented_posts_cache' );
}
add_action( 'wp_update_comment_count', 'invalidate_sb_top_commented_posts_cache' );
// enqueue script
function my_scripts_method() {
if ( !is_admin() ) {
wp_enqueue_script('jquery-ui-accordion');
wp_enqueue_script(
'custom-accordion',
get_stylesheet_directory_uri() . '/js/accordion.js',
array('jquery')
);
}
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
?>