質問編集履歴

1

functions.phpの内容を追記

2019/12/19 07:35

投稿

qpooooh
qpooooh

スコア11

test CHANGED
File without changes
test CHANGED
@@ -45,3 +45,385 @@
45
45
  不足している情報などございましたら、ご指摘いただけますと幸いです。
46
46
 
47
47
  ご教示のほど、よろしくお願いいたします。
48
+
49
+
50
+
51
+ ---
52
+
53
+ 追記:functions.php
54
+
55
+
56
+
57
+ ```php
58
+
59
+ <?php
60
+
61
+ /**
62
+
63
+ * themefile functions and definitions
64
+
65
+ *
66
+
67
+ * @link https://developer.wordpress.org/themes/basics/theme-functions/
68
+
69
+ *
70
+
71
+ * @package themefile
72
+
73
+ */
74
+
75
+
76
+
77
+ if ( ! function_exists( 'themefile_setup' ) ) :
78
+
79
+ /**
80
+
81
+ * Sets up theme defaults and registers support for various WordPress features.
82
+
83
+ *
84
+
85
+ * Note that this function is hooked into the after_setup_theme hook, which
86
+
87
+ * runs before the init hook. The init hook is too late for some features, such
88
+
89
+ * as indicating support for post thumbnails.
90
+
91
+ */
92
+
93
+ function themefile_setup() {
94
+
95
+ /*
96
+
97
+ * Make theme available for translation.
98
+
99
+ * Translations can be filed in the /languages/ directory.
100
+
101
+ * If you're building a theme based on themefile, use a find and replace
102
+
103
+ * to change 'themefile' to the name of your theme in all the template files.
104
+
105
+ */
106
+
107
+ load_theme_textdomain( 'themefile', get_template_directory() . '/languages' );
108
+
109
+
110
+
111
+ // Add default posts and comments RSS feed links to head.
112
+
113
+ add_theme_support( 'automatic-feed-links' );
114
+
115
+
116
+
117
+ /*
118
+
119
+ * Let WordPress manage the document title.
120
+
121
+ * By adding theme support, we declare that this theme does not use a
122
+
123
+ * hard-coded <title> tag in the document head, and expect WordPress to
124
+
125
+ * provide it for us.
126
+
127
+ */
128
+
129
+ add_theme_support( 'title-tag' );
130
+
131
+
132
+
133
+ /*
134
+
135
+ * Enable support for Post Thumbnails on posts and pages.
136
+
137
+ *
138
+
139
+ * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
140
+
141
+ */
142
+
143
+ add_theme_support( 'post-thumbnails' );
144
+
145
+
146
+
147
+ // This theme uses wp_nav_menu() in one location.
148
+
149
+ register_nav_menus( array(
150
+
151
+ 'menu-1' => esc_html__( 'Primary', 'themefile' ),
152
+
153
+ ) );
154
+
155
+
156
+
157
+ /*
158
+
159
+ * Switch default core markup for search form, comment form, and comments
160
+
161
+ * to output valid HTML5.
162
+
163
+ */
164
+
165
+ add_theme_support( 'html5', array(
166
+
167
+ 'search-form',
168
+
169
+ 'comment-form',
170
+
171
+ 'comment-list',
172
+
173
+ 'gallery',
174
+
175
+ 'caption',
176
+
177
+ ) );
178
+
179
+
180
+
181
+ // Set up the WordPress core custom background feature.
182
+
183
+ add_theme_support( 'custom-background', apply_filters( 'themefile_custom_background_args', array(
184
+
185
+ 'default-color' => 'ffffff',
186
+
187
+ 'default-image' => '',
188
+
189
+ ) ) );
190
+
191
+
192
+
193
+ // Add theme support for selective refresh for widgets.
194
+
195
+ add_theme_support( 'customize-selective-refresh-widgets' );
196
+
197
+
198
+
199
+ /**
200
+
201
+ * Add support for core custom logo.
202
+
203
+ *
204
+
205
+ * @link https://codex.wordpress.org/Theme_Logo
206
+
207
+ */
208
+
209
+ add_theme_support( 'custom-logo', array(
210
+
211
+ 'height' => 250,
212
+
213
+ 'width' => 250,
214
+
215
+ 'flex-width' => true,
216
+
217
+ 'flex-height' => true,
218
+
219
+ ) );
220
+
221
+ }
222
+
223
+ endif;
224
+
225
+ add_action( 'after_setup_theme', 'themefile_setup' );
226
+
227
+
228
+
229
+ /**
230
+
231
+ * Set the content width in pixels, based on the theme's design and stylesheet.
232
+
233
+ *
234
+
235
+ * Priority 0 to make it available to lower priority callbacks.
236
+
237
+ *
238
+
239
+ * @global int $content_width
240
+
241
+ */
242
+
243
+ function themefile_content_width() {
244
+
245
+ // This variable is intended to be overruled from themes.
246
+
247
+ // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
248
+
249
+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
250
+
251
+ $GLOBALS['content_width'] = apply_filters( 'themefile_content_width', 640 );
252
+
253
+ }
254
+
255
+ add_action( 'after_setup_theme', 'themefile_content_width', 0 );
256
+
257
+
258
+
259
+ /**
260
+
261
+ * Register widget area.
262
+
263
+ *
264
+
265
+ * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
266
+
267
+ */
268
+
269
+ function themefile_widgets_init() {
270
+
271
+ register_sidebar( array(
272
+
273
+ 'name' => esc_html__( 'Sidebar', 'themefile' ),
274
+
275
+ 'id' => 'sidebar-1',
276
+
277
+ 'description' => esc_html__( 'Add widgets here.', 'themefile' ),
278
+
279
+ 'before_widget' => '<section id="%1$s" class="widget %2$s">',
280
+
281
+ 'after_widget' => '</section>',
282
+
283
+ 'before_title' => '<h2 class="widget-title">',
284
+
285
+ 'after_title' => '</h2>',
286
+
287
+ ) );
288
+
289
+ }
290
+
291
+ add_action( 'widgets_init', 'themefile_widgets_init' );
292
+
293
+
294
+
295
+ /**
296
+
297
+ * Enqueue scripts and styles.
298
+
299
+ */
300
+
301
+ function themefile_scripts() {
302
+
303
+ //wp_enqueue_style( 'themefile-style', get_stylesheet_uri() );
304
+
305
+
306
+
307
+ wp_enqueue_script( 'themefile-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
308
+
309
+
310
+
311
+ wp_enqueue_script( 'themefile-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
312
+
313
+
314
+
315
+ if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
316
+
317
+ wp_enqueue_script( 'comment-reply' );
318
+
319
+ }
320
+
321
+ }
322
+
323
+ add_action( 'wp_enqueue_scripts', 'themefile_scripts' );
324
+
325
+
326
+
327
+ /**
328
+
329
+ * Implement the Custom Header feature.
330
+
331
+ */
332
+
333
+ require get_template_directory() . '/inc/custom-header.php';
334
+
335
+
336
+
337
+ /**
338
+
339
+ * Custom template tags for this theme.
340
+
341
+ */
342
+
343
+ require get_template_directory() . '/inc/template-tags.php';
344
+
345
+
346
+
347
+ /**
348
+
349
+ * Functions which enhance the theme by hooking into WordPress.
350
+
351
+ */
352
+
353
+ require get_template_directory() . '/inc/template-functions.php';
354
+
355
+
356
+
357
+ /**
358
+
359
+ * Customizer additions.
360
+
361
+ */
362
+
363
+ require get_template_directory() . '/inc/customizer.php';
364
+
365
+
366
+
367
+ /**
368
+
369
+ * Load Jetpack compatibility file.
370
+
371
+ */
372
+
373
+ if ( defined( 'JETPACK__VERSION' ) ) {
374
+
375
+ require get_template_directory() . '/inc/jetpack.php';
376
+
377
+ }
378
+
379
+
380
+
381
+
382
+
383
+ //固定ページの親ページをスラッグ判定
384
+
385
+ function is_parent_slug() {
386
+
387
+ global $post;
388
+
389
+ if ($post->post_parent) {
390
+
391
+ $post_data = get_post($post->post_parent);
392
+
393
+ return $post_data->post_name;
394
+
395
+ }
396
+
397
+ }
398
+
399
+
400
+
401
+ /* 投稿アーカイブページの作成 */
402
+
403
+ function post_has_archive( $args, $post_type ) {
404
+
405
+
406
+
407
+ if ( 'post' == $post_type ) {
408
+
409
+ $args['rewrite'] = true;
410
+
411
+ $args['has_archive'] = 'news'; //任意のスラッグ名
412
+
413
+ }
414
+
415
+ return $args;
416
+
417
+
418
+
419
+ }
420
+
421
+ add_filter( 'register_post_type_args', 'post_has_archive', 10, 2 );
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+ ```