У меня есть следующая структура папок для моей темы:
theme
inc
theme
functions.php
init.php
functions.php
В inc / theme / functions.php я размещаю все функции, относящиеся к теме (например, удаление таксономий и т. Д.)).В theme / functions.php у меня есть все основные функции.
С моим текущим кодом WordPress заявляет: «Сайт испытывает технические трудности».Если я удаляю все в theme / functions.php , содержимое загружается, но код в inc / theme / functions.php не выполняется.Например, в inc / theme / functions.php у меня есть wp_enqueue_style( 'style', get_stylesheet_uri() );
, и ни один из стилей не работает.
Не могу понять:
- Почему theme / functions.php вызывает ошибку WordPress.
- Почему inc / theme / functions.php не выполняется.
theme / functions.php
<?php
require_once trailingslashit( get_template_directory() ) . 'inc/init.php';
new theme_ThemeFunctions;
class theme_ThemeFunctions {
function __construct() {
load_theme_textdomain( 'theme' );
add_action( 'init', array( $this, 'post_types_taxonomies' ) );
add_action( 'init', array( $this, 'register_menus' ) );
}
public function post_types_taxonomies() {
register_post_type(
'case-studies',
build_post_args(
'case-study', 'Case study', 'Case studies',
array(
'menu_icon' => 'dashicons-book',
'menu_position' => 20,
'has_archive' => true
)
)
);
}
public function register_menus() {
register_nav_menus(
array(
'main' => __( 'Main Menu', 'theme' ),
)
);
}
}
?>
inc / theme / functions.php
<?php
function scriptAndStyles() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'scriptAndStyles' );
function remove_editor() {
remove_post_type_support('page', 'editor');
}
add_action('admin_init', 'remove_editor');
// Remove featured image option from pages
function remove_thumbnail_box() {
remove_meta_box( 'postimagediv','page', 'side' );
}
add_action('do_meta_boxes', 'remove_thumbnail_box');
// Remove posts type option
function post_remove () {
remove_menu_page('edit.php');
}
add_action('admin_menu', 'post_remove');
?>
inc / init.php
<?php
$include_dir = trailingslashit( get_template_directory() ) . 'inc/';
// Load any custom functions
require_once $include_dir . 'theme/functions.php';
?>