-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
249 lines (215 loc) · 7.45 KB
/
functions.php
File metadata and controls
249 lines (215 loc) · 7.45 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
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
<?php
/**
* Basic Starter Theme functions and definitions
*
* @package simplewrite
*/
if ( ! defined( 'SWRT_VERSION' ) ) {
define( 'SWRT_VERSION', '1.0.0' );
}
/**
* Theme setup
*/
function swrt_setup() {
load_theme_textdomain( 'simplewrite', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'customize-selective-refresh-widgets' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'wp-block-styles' );
add_theme_support( 'align-wide' );
add_theme_support(
'custom-logo',
array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
)
);
add_theme_support(
'custom-background',
apply_filters(
'swrt_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => '',
)
)
);
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
'navigation-widgets',
)
);
register_nav_menus(
array(
'menu-1' => esc_html__( 'Primary', 'simplewrite' ),
'footer' => esc_html__( 'Footer Menu', 'simplewrite' ),
)
);
// Load editor styles
add_editor_style( 'editor-style.css' );
}
add_action( 'after_setup_theme', 'swrt_setup' );
function swrt_register_block_styles() {
register_block_style(
'core/image',
array(
'name' => 'fancy-border',
'label' => __( 'Fancy Border', 'simplewrite' ),
'inline_style' => '.is-style-fancy-border { border: 5px double #000; padding: 10px; }',
)
);
register_block_pattern(
'simplewrite/hero-text',
array(
'title' => __( 'Hero Text Section', 'simplewrite' ),
'description' => _x( 'A centered hero section with text.', 'Block pattern description', 'simplewrite' ),
'content' => "<!-- wp:paragraph {\"align\":\"center\",\"fontSize\":\"large\"} --><p class=\"has-text-align-center has-large-font-size\">" . esc_html__('Welcome to Our Website!', 'simplewrite') . "</p><!-- /wp:paragraph -->",
)
);
}
add_action( 'init', 'swrt_register_block_styles' );
/**
* Set the content width
*/
function swrt_content_width() {
$GLOBALS['content_width'] = apply_filters( 'swrt_content_width', 640 );
}
add_action( 'after_setup_theme', 'swrt_content_width', 0 );
/**
* Register widget area
*/
function swrt_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'simplewrite' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'simplewrite' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Footer Widget Area', 'simplewrite' ),
'id' => 'footer-1',
'description' => esc_html__( 'Add widgets here.', 'simplewrite' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'swrt_widgets_init' );
/**
* Enqueue scripts and styles
*/
function swrt_scripts() {
wp_enqueue_style( 'swrt-style', get_stylesheet_uri(), array(), SWRT_VERSION );
wp_style_add_data( 'swrt-style', 'rtl', 'replace' );
wp_enqueue_script(
'swrt-navigation',
get_template_directory_uri() . '/js/navigation.js',
array(),
SWRT_VERSION,
true
);
wp_enqueue_script(
'swrt-custom',
get_template_directory_uri() . '/js/custom.js',
array('jquery'), // if your JS depends on jQuery
SWRT_VERSION,
true
);
// Customizer live preview
if ( is_customize_preview() ) {
wp_enqueue_script(
'swrt-customizer',
get_template_directory_uri() . '/js/customizer.js',
array( 'jquery', 'customize-preview' ),
SWRT_VERSION,
true
);
}
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'swrt_scripts' );
/**
* Custom Navigation Walker for better accessibility
*/
class SWRT_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_el(&$output, $item, $depth = 0, $args = null, $id = 0) {
$indent = ($depth) ? str_repeat("\t", $depth) : '';
$classes = empty($item->classes) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
// Add has-children class if item has children
if (in_array('menu-item-has-children', $classes)) {
$classes[] = 'has-children';
}
$class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
$class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';
$id = apply_filters('nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args);
$id = $id ? ' id="' . esc_attr($id) . '"' : '';
$output .= $indent . '<li' . $id . $class_names .'>';
$attributes = ! empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) .'"' : '';
$attributes .= ! empty($item->target) ? ' target="' . esc_attr($item->target ) .'"' : '';
$attributes .= ! empty($item->xfn) ? ' rel="' . esc_attr($item->xfn ) .'"' : '';
$attributes .= ! empty($item->url) ? ' href="' . esc_attr($item->url ) .'"' : '';
// Add ARIA attributes for items with children
if (in_array('menu-item-has-children', $classes)) {
$attributes .= ' aria-haspopup="true"';
$attributes .= ' aria-expanded="false"';
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
// Add chevron icon only if has children
if (in_array('menu-item-has-children', $classes)) {
$item_output .= ' <span class="submenu-icon" aria-hidden="true"></span>';
}
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
}
}
/**
* Include theme files
*/
require get_template_directory() . '/inc/custom-header.php';
require get_template_directory() . '/inc/template-tags.php';
require get_template_directory() . '/inc/template-functions.php';
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/blog-functions.php';
require get_template_directory() . '/inc/widgets.php';
require get_template_directory() . '/inc/theme-colors.php';
require get_template_directory() . '/inc/custom-post-types.php';
if ( defined( 'JETPACK__VERSION' ) ) {
require get_template_directory() . '/inc/jetpack.php';
}
/**
* Enqueue admin styles
*/
function swrt_admin_styles($hook) {
// The theme no longer registers a separate admin settings page.
// All theme options are exposed via the Customizer API. This
// function is intentionally left empty to avoid enqueuing admin
// assets for a non-existent settings page.
}
// Historically this theme added a top-level settings page. That
// practice is not allowed; do not register admin pages from themes.