-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
185 lines (164 loc) · 4.23 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
<?php
/**
* Functions and definitions
*
* @package Harmony
* @since 1.0.0
*/
namespace Harmony;
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Direct script access denied.' );
}
/* /////////////////////// Update Version Here. //////////////////// */
define( 'HARMONY_VERSION', '1.0.2' );
define( 'HARMONY_THEME', 'harmony' );
define( 'HARMONY_DIR', rtrim( get_template_directory(), '/' ) );
define( 'HARMONY_URL', rtrim( get_template_directory_uri(), '/' ) );
/**
* Theme setup.
*
* @since 1.0.0
*/
add_action( 'after_setup_theme', __NAMESPACE__.'\setup_theme' );
function setup_theme()
{
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentysixteen
* If you're building a theme based on harmony, use a find and replace
* to change 'harmony' to the name of your theme in all the template files
*/
load_theme_textdomain( 'harmony',
get_template_directory_uri() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Let WordPress manage the document title.
add_theme_support( 'title-tag' );
// Enable support for Post Thumbnails.
add_theme_support( 'post-thumbnails' );
// Admin editor styles.
add_theme_support( 'editor-styles' );
// Add support for responsive embeds.
//add_theme_support( 'responsive-embeds' );
// Add theme support for selective refresh for widgets.
//add_theme_support( 'customize-selective-refresh-widgets' );
// Enqueue editor styles.
add_editor_style();
/*
* Enable support for custom logo.
*
* @since Harmony 1.2
*/
add_theme_support(
'custom-logo',
array(
'height' => 420,
'width' => 680,
'flex-height' => true,
)
);
// add primary menu
register_nav_menus(
array(
'primary' => __( 'Primary Menu', 'harmony' ),
'secondary' => __( 'Very Top Menu', 'harmony' ),
)
);
}
/**
* Enqueue scripts and styles.
*
* @since 1.0.0
*/
add_action(
'wp_enqueue_scripts', __NAMESPACE__.'\enqueue_scripts' );
function enqueue_scripts()
{
wp_enqueue_style( 'harmony-style',
HARMONY_URL . '/style.css',
array(),
HARMONY_VERSION
);
wp_enqueue_script( 'harmony-theme-script',
HARMONY_URL . '/includes/harmony-theme.js',
array( 'jquery' ),
HARMONY_VERSION,
false
);
// rtl style
wp_style_add_data( 'harmony-style',
'rtl',
'replace'
);
// comment scripts
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script(
'comment-reply'
);
}
}
/** #A4
* Registers a widget area.
*
* @link https://developer.wordpress.org/reference/functions/register_sidebar/
*
* @since themename 1.0
*/
add_action(
'widgets_init', __NAMESPACE__.'\load_widgets' );
function load_widgets()
{
register_sidebar(
array(
'name' => __( 'Primary Sidebar', 'harmony' ),
'id' => 'sidebar-primary',
'description' => __( 'Appears before the footer section', 'harmony' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
/**
* Returns a custom logo, linked to home
*
* @since 1.0.1
*/
add_action(
'harmony_render_logo', __NAMESPACE__.'\render_logo' );
function render_logo()
{
if( has_custom_logo() ) :
$logourl = esc_url( wp_get_attachment_url( get_theme_mod( 'custom_logo' ) ) );
echo '<img src="'. esc_url( $logourl ) .'"
alt="'. esc_attr( get_bloginfo( 'name' ) ) .'" class="harmony-logo"/>';
endif;
}
/**
* Return post thumbnail on excerpts
*
* @since 1.0.1
* @return Boolean
*/
add_action( 'harmony_thumbnail', __NAMESPACE__.'\render_thumbnail' );
function render_thumbnail()
{
// If there are images
if ( has_post_thumbnail() ) {
echo '<figure class="harmony-has-thumbnail">';
the_post_thumbnail();
echo '</figure>';
} else {
echo '<span class="harmony-not-thumbnail"></span>';
}
}
/**
* Include helper files
*
* @since 1.0.0
*/
require( HARMONY_DIR . '/includes/customizer.php' );
if ( is_admin() ) :
require( HARMONY_DIR . '/includes/theme-admin-menu.php' );
endif;