如何在子functions.php中覆盖父functions.php

时间:2018-07-29 09:30:53

标签: php wordpress wordpress-theming

我正在寻找有关如何替代或替换父主题中加载的某些功能并将其移入子主题的一些建议,以便我们可以对子主题中的文件本身进行更改。

我们已经将父主题的结构和文件复制到了子主题中,但是尚无法找到防止父主题加载和加载子主题文件的方法。

基本上,下面列出的所有require文件都将在子主题中进行复制和更改,但需要找到某种方法来替代父项functions.php

我们已经尝试了多种方法来执行此操作,但到目前为止似乎还无法正常工作。

这是当前的父functions.php文件:

/**
 * moto functions and definitions
 *
 * @package moto
 */
if ( ! function_exists( 'moto_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function moto_setup() {

    global $pagenow;
    if ( is_admin() && 'themes.php' == $pagenow && isset( $_GET['activated'] ) ) {
        wp_redirect(admin_url("options-general.php?page=moto-system-status")); // Your admin page URL
        exit();
    }
    /* snip irrelevant code */

}
endif; // moto_setup
add_action( 'after_setup_theme', 'moto_setup' );

/* snip irrelevant code */

add_action( 'after_setup_theme', 'moto_content_width', 0 );
/**
 * Register widget area.
 *
 * @link http://codex.wordpress.org/Function_Reference/register_sidebar
 */
function moto_widgets_init() {
/* snip irrelevant code */
}
add_action( 'widgets_init', 'moto_widgets_init' );
/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/function/custom-header.php';
/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/function/template-tags.php';
/**
 * Custom functions that act independently of the theme templates.
 */
require get_template_directory() . '/function/extras.php';
/**
 * Customizer additions.
 */
require get_template_directory() . '/function/customizer.php';
/**
 * Load Jetpack compatibility file. 
 */ 
require get_template_directory() . '/function/jetpack.php';

require_once get_template_directory() . '/include/aq_resizer.php';
require_once get_template_directory() . '/include/moto-sys-req.php';
require_once get_template_directory() . '/include/moto-enqueue.php';
require_once get_template_directory() . '/include/moto-functions.php';
require_once get_template_directory() . '/include/theme_plugin/plugin-activate-config.php';
require_once get_template_directory() . '/include/wordpress-reset.php';

有什么建议吗?

谢谢。

0 个答案:

没有答案
相关问题