Wordpress-不要在单页模板上加载functions.php

时间:2018-09-03 04:21:26

标签: wordpress

我正在构建一个超级基本的WordPress单页模板,其中使用了一些过滤器禁用了所有插件。

当我尝试加载页面时出现错误,因为在functions.php文件中,它为前一个开发人员完成的各种待加载插件提取了几个函数。由于已将其禁用,因此处理过程将发生致命错误。

如果不在我正在使用的单个页面模板上,那么可以跳过对functions.php文件的加载,而不是用function_exists检查替换每个点吗?

2 个答案:

答案 0 :(得分:0)

一个快速解决方案是重命名/备份以前的开发人员functions.php文件,然后创建一个新的空functions.php文件。例如,使用bash shell终端:

mv /wp-content/themes/your-theme-here/functions.php /wp-content/themes/your-theme-here/functions.php.bkup

touch /wp-content/themes/your-theme-here/functions.php

mv-是移动/重命名命令,第一个参数是要移动(重命名)的文件,第二个参数是要将文件移动(重命名)的位置。

touch-提供一种创建新文件的方法。

然后,您可以使用项目仍需要的任何功能填充这个新的functions.php文件。

答案 1 :(得分:0)

困难在于wp-settings.php总是加载模板的function.php。

但是,由于functions.php文件几乎是在WordPress处理的最后加载的,我认为您可以使用操作'setup_theme'来接管WordPress处理,并将其余的WordPress处理作为wp-blog进行-header.php除了跳过functions.php的加载外,会有其他情况。

add_action( 'setup_theme', function() {
    if ( $use_my_singlular_page_template ) {
        // Define the template related constants.
        wp_templating_constants(  );

        // Load the default text localization domain.
        load_default_textdomain();

        $locale = get_locale();
        $locale_file = WP_LANG_DIR . "/$locale.php";
        if ( ( 0 === validate_file( $locale ) ) && is_readable( $locale_file ) )
            require( $locale_file );
        unset( $locale_file );

        /**
         * WordPress Locale object for loading locale domain date and various strings.
         * @global WP_Locale $wp_locale
         * @since 2.1.0
         */
        $GLOBALS['wp_locale'] = new WP_Locale();

        /**
         *  WordPress Locale Switcher object for switching locales.
         *
         * @since 4.7.0
         *
         * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object.
         */
        $GLOBALS['wp_locale_switcher'] = new WP_Locale_Switcher();
        $GLOBALS['wp_locale_switcher']->init();

        /*
         * don't load theme's function.php

        // Load the functions for the active theme, for both parent and child theme if applicable.
        if ( ! wp_installing() || 'wp-activate.php' === $pagenow ) {
            if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) )
                include( STYLESHEETPATH . '/functions.php' );
            if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
                include( TEMPLATEPATH . '/functions.php' );
        }
         */

        /**
         * Fires after the theme is loaded.
         *
         * @since 3.0.0
         */
        do_action( 'after_setup_theme' );

        // Set up current user.
        $GLOBALS['wp']->init();

        /**
         * Fires after WordPress has finished loading but before any headers are sent.
         *
         * Most of WP is loaded at this stage, and the user is authenticated. WP continues
         * to load on the {@see 'init'} hook that follows (e.g. widgets), and many plugins instantiate
         * themselves on it for all sorts of reasons (e.g. they need a user, a taxonomy, etc.).
         *
         * If you wish to plug an action once WP is loaded, use the {@see 'wp_loaded'} hook below.
         *
         * @since 1.5.0
         */
        do_action( 'init' );

        // Check site status
        if ( is_multisite() ) {
            if ( true !== ( $file = ms_site_check() ) ) {
                require( $file );
                die();
            }
            unset($file);
        }

        /**
         * This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
         *
         * Ajax requests should use wp-admin/admin-ajax.php. admin-ajax.php can handle requests for
         * users not logged in.
         *
         * @link https://codex.wordpress.org/AJAX_in_Plugins
         *
         * @since 3.0.0
         */
        do_action( 'wp_loaded' );

        // do the remaining parts of wp-blog-header.php

        // Set up the WordPress query.
        wp();

        // Load the theme template.
        require_once( ABSPATH . WPINC . '/template-loader.php' );

        // everything is done; must not return!
        exit();
    }
} );