-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
148 lines (132 loc) · 4.08 KB
/
functions.php
File metadata and controls
148 lines (132 loc) · 4.08 KB
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
<?php
/**
* Devstarter - Functions and Definitions
*
* @package devstarter
* @version 1.0.0
* @author Muhammad Abid
* @link https://muhammadabid.com
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'DEVSTARTER_VERSION', '1.0.1' );
define( 'DEVSTARTER_DIR', get_template_directory() );
define( 'DEVSTARTER_URI', get_template_directory_uri() );
/**
* Include theme modules
*/
require_once DEVSTARTER_DIR . '/inc/theme-support.php';
require_once DEVSTARTER_DIR . '/inc/enqueue.php';
require_once DEVSTARTER_DIR . '/inc/custom-post-types.php';
require_once DEVSTARTER_DIR . '/inc/widgets.php';
require_once DEVSTARTER_DIR . '/inc/customizer.php';
require_once DEVSTARTER_DIR . '/inc/page-builders.php';
/**
* Set content width for embeds and media
*/
if ( ! isset( $content_width ) ) {
$content_width = 1200;
}
/**
* Register custom image sizes
*/
function devstarter_custom_image_sizes() {
add_image_size( 'devstarter-featured', 800, 450, true );
add_image_size( 'devstarter-thumbnail', 400, 300, true );
add_image_size( 'devstarter-square', 600, 600, true );
add_image_size( 'devstarter-hero', 1920, 800, true );
}
add_action( 'after_setup_theme', 'devstarter_custom_image_sizes' );
/**
* Make custom sizes available in media uploader
*/
function devstarter_custom_image_size_names( $sizes ) {
return array_merge( $sizes, array(
'devstarter-featured' => __( 'Featured (800x450)', 'devstarter' ),
'devstarter-thumbnail' => __( 'Thumbnail (400x300)', 'devstarter' ),
'devstarter-square' => __( 'Square (600x600)', 'devstarter' ),
'devstarter-hero' => __( 'Hero (1920x800)', 'devstarter' ),
) );
}
add_filter( 'image_size_names_choose', 'devstarter_custom_image_size_names' );
/**
* Excerpt length
*/
function devstarter_excerpt_length( $length ) {
return 25;
}
add_filter( 'excerpt_length', 'devstarter_excerpt_length' );
/**
* Excerpt ending
*/
function devstarter_excerpt_more( $more ) {
return '…';
}
add_filter( 'excerpt_more', 'devstarter_excerpt_more' );
/**
* Pagination
*/
function devstarter_pagination() {
the_posts_pagination( array(
'mid_size' => 2,
'prev_text' => '« ' . __( 'Previous', 'devstarter' ),
'next_text' => __( 'Next', 'devstarter' ) . ' »',
'screen_reader_text' => __( 'Posts navigation', 'devstarter' ),
) );
}
/**
* Post date output
*/
function devstarter_posted_on() {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string .= '<time class="updated screen-reader-text" datetime="%3$s">%4$s</time>';
}
printf(
'<span class="posted-on">' . $time_string . '</span>',
esc_attr( get_the_date( DATE_W3C ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( DATE_W3C ) ),
esc_html( get_the_modified_date() )
);
}
/**
* Post author output
*/
function devstarter_posted_by() {
printf(
'<span class="byline"> %s <a href="%s" rel="author">%s</a></span>',
esc_html__( 'by', 'devstarter' ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_html( get_the_author() )
);
}
/**
* Comment count link
*/
function devstarter_comment_count() {
if ( ! post_password_required() && comments_open() ) {
echo '<span class="comments-link">';
comments_popup_link(
__( 'Leave a comment', 'devstarter' ),
__( '1 Comment', 'devstarter' ),
__( '% Comments', 'devstarter' )
);
echo '</span>';
}
}
/**
* Returns layout class from customizer setting
*/
function devstarter_get_layout_class() {
$position = get_theme_mod( 'devstarter_sidebar_position', 'right' );
switch ( $position ) {
case 'left':
return 'devstarter-layout devstarter-layout--left-sidebar';
case 'none':
return 'devstarter-layout devstarter-layout--full-width';
default:
return 'devstarter-layout';
}
}