-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.php
143 lines (104 loc) · 3.39 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
<?php
add_action( 'after_setup_theme', 'wpdocs_theme_setup' );
function wpdocs_theme_setup() {
load_theme_textdomain( 'legalizebelarus', get_template_directory() . '/languages' );
}
require_once( 'bs4navwalker.php' );
register_nav_menu( 'top', 'Top menu' );
function themebs_enqueue_styles() {
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css' );
wp_enqueue_style( 'core', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'themebs_enqueue_styles' );
function themebs_enqueue_scripts() {
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.bundle.min.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'themebs_enqueue_scripts' );
add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
function set_default_meta( $post_ID ) {
$post_meta_labels = array( "author", "custom_license", "disable_thumbnail", "custom_license_image" );
$default_metas = array( "Legalize Belarus", "0", "0", "0");
for ( $i = 0; $i <= count( $post_meta_labels ); $i ++ ) {
$current_field_value = get_post_meta( $post_ID, $post_meta_labels[ $i ], true );
$default_meta = $default_metas[ $i ];
if ( $current_field_value == '' && ! wp_is_post_revision( $post_ID ) ) {
add_post_meta( $post_ID, $post_meta_labels[ $i ], $default_meta, true );
}
}
return $post_ID;
}
add_action( 'wp_insert_post', 'set_default_meta' );
function getPostViews( $postID ) {
$count_key = 'post_views_count';
$count = get_post_meta( $postID, $count_key, true );
if ( $count == '' ) {
delete_post_meta( $postID, $count_key );
add_post_meta( $postID, $count_key, '0' );
return "0";
}
return $count;
}
function setPostViews( $postID ) {
$count_key = 'post_views_count';
$count = get_post_meta( $postID, $count_key, true );
if ( $count == '' ) {
$count = 0;
delete_post_meta( $postID, $count_key );
add_post_meta( $postID, $count_key, '0' );
} else {
$count ++;
update_post_meta( $postID, $count_key, $count );
}
}
if ( function_exists( 'register_sidebar' ) ) {
register_sidebar( array(
'name' => 'posts-sidebar',
'before_widget' => '
<div class="widgetizedArea py-1">',
'after_widget' => '
</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
}
if ( function_exists( 'register_sidebar' ) ) {
register_sidebar( array(
'name' => 'main-sidebar',
'before_widget' => '
<div class="widgetizedArea py-1">',
'after_widget' => '
</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
}
add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );
function limit_posts_per_archive_page() {
if ( is_category() ) {
$limit = 5;
} elseif ( is_search() ) {
$limit = 5;
} else {
$limit = get_option( 'posts_per_page' );
}
set_query_var( 'posts_per_archive_page', $limit );
}
add_filter( 'pre_get_posts', 'limit_posts_per_archive_page' );
function filter_pre_handle_404( $preempt, $wp_query ) {
if ( isset( $wp_query->query['page'] ) && $wp_query->query['page'] ) {
return true;
}
return $preempt;
}
add_filter( 'pre_handle_404', 'filter_pre_handle_404', 10, 2 );
function aj_modify_posts_per_page( $query ) {
if ( $query->is_search() ) {
$query->set( 'posts_per_page', '25' );
}
}
add_action( 'pre_get_posts', 'aj_modify_posts_per_page' );
add_post_type_support( 'page', 'excerpt' );
?>