-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.php
228 lines (189 loc) · 7.07 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
<?php
/**
* All our theme functions etc.
*
* @package Falcon633
*/
/**
* Set theme up, also note here what we support feature wise.
*/
function falcon_setup() {
// We don't supply a title tag in header.php
add_theme_support( 'title-tag' );
// Default posts/comments RSS feed links to head.
// Note, comments might not be supported so could need updating
add_theme_support( 'automatic-feed-links' );
// Plan to add support for post thumbnails...
add_theme_support( 'post-thumbnails' );
// Header uses wp_nav_menu() at two points.
register_nav_menus( array(
'primary_nav' => esc_html__( 'Primary Menu', 'falcon' ),
'footer_nav' => esc_html__( 'Footer Menu', 'falcon' ),
'external_nav' => esc_html__( 'External/Social Menu', 'falcon' ),
'mobile_nav' => esc_html__( 'Pull-down Main Mobile Menu', 'falcon' ),
'mobile_contact'=> esc_html__( 'Speech-icon/contact Mobile Button', 'falcon' ),
) );
/*
* Use HTML5 standard markup for...
*/
add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption',
) );
/*
* Add support for styling quotes in a cool way
* Other post formats listed: https://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array('quote') );
}
add_action( 'after_setup_theme', 'falcon_setup' );
/**
* Register our only widget area
*/
function falcon_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Home Widget Area', 'falcon' ),
'id' => 'home-widgets-1',
'description' => 'Widget area that appears on the home page.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => get_falcon_section_header_open(),
'after_title' => get_falcon_section_header_close(),
) );
register_sidebar( array(
'name' => esc_html__( 'Post Widget Area', 'falcon' ),
'id' => 'post-widgets-1',
'description' => 'Widget area that appears after every single post.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'falcon_widgets_init' );
/**
* Load our theme styles.
*/
function falcon_scripts() {
wp_enqueue_style( 'oppan-falcon-style', get_stylesheet_uri() );
wp_enqueue_style( 'font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css' );
}
add_action( 'wp_enqueue_scripts', 'falcon_scripts' );
/**
* Set post mail handling (we use JetPack)
*
* Further examples can be found:
* https://jetpack.com/support/subscriptions/#customize-confirmation
*/
add_filter( 'jetpack_allow_per_post_subscriptions', '__return_true' ); // allow per post override
function falcon_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date( 'd M Y') )
);
$posted_on = '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>';
echo '<span class="posted-on">' . $posted_on . '</span>';
}
/**
* Pagination
*/
// We need just a little more control of the next/prev links to keep things neat,
// so we add a class to each respectively
add_filter('next_posts_link_attributes', function($e) { return 'class="next-link"'; });
add_filter('previous_posts_link_attributes', function($e) { return 'class="prev-link"'; });
// Return pagination for theme archive pages
function falcon_pagination() {
global $wp_query;
$out = '<div class="falcon-pagination-wrapper">';
// If a prev or next link isn't available we make a placeholder anchor tag.
// This is a coherent way for us to keep the spacing the same regardless of
// whether there is a prev/next link available.
if (get_previous_posts_link()) {
$out .= get_previous_posts_link('<i class="prev-arrow"></i>');
} else {
$out .= '<a class="prev-link"> </a>';
}
$big = 999999999; // need an unlikely integer
$out .= paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'prev_next' => false,
) );
if (get_next_posts_link()) {
$out .= get_next_posts_link('<i class="next-arrow"></i>');
} else {
$out .= '<a class="next-link"> </a>';
}
$out .= '</div>';
return $out;
}
/* Use a shorter than normal excerpt length */
function custom_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 100);
// Replaces [..] with read on links
function modify_read_more_link() {
return '<a class="read-more" href="' . get_permalink() . '">Read On</a>';
}
add_filter( 'the_content_more_link', 'modify_read_more_link' );
function new_excerpt_more($more) {
global $post;
return '... <a class="read-more" href="'. get_permalink($post->ID) . '">Read On</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
/*
* Take the blog title, assumed to a domain.
* Find the first dot and use alternative colour for everything after this.
* e.g. falkus _.co._, foo _.bar.uk_
*/
function site_heading_tag() {
$name = get_bloginfo('name');
$dot_post = strpos($name, '.');
return '<h1>' . substr($name, 0, $dot_post) . '<span class="alternative-colour">' . substr($name, $dot_post) . '</span></h1>';
}
/*
* Try get the first URL from mobile_contact menu, failing that return the
* homepage URL for this blog.
*/
function falcon_contact_url() {
// mobile_contact is the specified menu we use for the contact button
$locations = get_nav_menu_locations();
$menu = get_term( $locations['mobile_contact'], 'nav_menu' );
$menu_items = wp_get_nav_menu_items($menu->term_id);
if (!$menu_items) {
return get_bloginfo('url');
}
$return_url = FALSE;
foreach ( $menu_items as $item ) {
$return_url = $item->url;
}
if (!$return_url) {
$return_url = get_bloginfo('url');
}
return $return_url;
}
function falcon_section_header_open($opt_class = '') {
echo get_falcon_section_header_open($opt_class);
}
function get_falcon_section_header_open($opt_class = '') {
$class = 'section-header';
if ($opt_class) {
$class .= ' ' . $opt_class;
}
return '<div class="' . $class . '">
<div class="section-header-inner">';
}
function falcon_section_header_close() {
echo get_falcon_section_header_close();
}
function get_falcon_section_header_close() {
return '</div>
<div class="indent-background"></div>
</div>';
}