Snippet: How to completely remove the Customizer settings of WP-Forge

remove-theme-customizer-settings

As I mentioned in a previous post, The very first snippet is a big one and it has been asked via email on various occasions and it was recently asked again. I thought this would be a great opportunity to start the snippets section of ThemeAwesome.com. Remember I hope to make this a weekly thing so if you have any ideas for snippets you would like to see, feel free to contact me and let me know, I’d be more than happy to try and get them on here.

The Big Question

Back in Feb, an issue was posted in WP-Forges’ Github issue area asking “removing customizer defaults – what’s the easy way to do this?” So far that question has gone unanswered and I hate to leave things undone.

Now the best way to accomplish this is to remove the action set by WP-Forge (or the parent if you are using a child theme), however none of the functions in the customizer are wrapped in a “if function exists”. I meant to do this in the latest version and for the life of me I don’t see how that got overlooked. Well that’s not going to happen again. We are going to add what is needed to WP-Forge. No need to worry, if you do not want to do this now the “if function_exists” wrappers we will be adding today will be available via the next update (which is also going to have some really cool things…can’t wait).

Let’s Begin

The first thing we need to do is open up customizer.php (located in the /inc/ folder) and look for the following:

function wpforge_customize_register( $wp_customize ) {

now above that line add this:

if ( ! function_exists( 'wpforge_customize_register' ) ) {

so now it should look like this:

if ( ! function_exists( 'wpforge_customize_register' ) ) {
  function wpforge_customize_register( $wp_customize ) {

Now scroll down and look for the following:

add_action( 'customize_register', 'wpforge_customize_register' );

and just below that add this:

}

Now it should look like this:

add_action( 'customize_register', 'wpforge_customize_register' );
}

This is going to allow us to remove the WP-Forge customizer settings all together, however the WordPress default settings will remain.

Next we need to wrap the inline css in a “if function_exists” statement. So lets go ahead and do that. Look for the following:

function wpforge_customize_css() { ?>

and just above it add this:

if ( ! function_exists( 'wpforge_customize_css' ) ) {

Now you should have this:

if ( ! function_exists( 'wpforge_customize_css' ) ) {
function wpforge_customize_css() { ?>

Now look for this:

add_action( 'wp_head', 'wpforge_customize_css', 100);

and just below it add this:

}

It should now look like this:

add_action( 'wp_head', 'wpforge_customize_css', 100);
}

Now we have the ability to completely remove the inline css that is added to the header area of WP-Forge when you activate the theme.

Remove Customizer from WP-Forge

Go ahead and open up functions.php. At the very end of the file let’s add our first function to remove the customizer settings, so add the following:

function remove_wpforge_customizer() {
    remove_action( 'customize_register', 'wpforge_customize_register' );
}
add_action( 'after_setup_theme', 'remove_wpforge_customizer', 9 );

This will remove the settings added by WP-Forge except for the default settings added by WordPress core. You will also notice that the inline css added to the header by WP-Forge is still there. So the next step is to remove them.

Now add the following to functions.php:

function remove_customizer_css() {
    remove_action('wp_head', 'wpforge_customize_css', 100);
}
add_action( 'after_setup_theme', 'remove_customizer_css', 9 );

Now your site will basically not be styled and you can begin building your site. There is one last way you can completely remove the customizer settings from WP-Forge and that is to comment out one particular line of code contained in functions.php. If that’s a route you want to take, look for the following in functions.php:

require( get_template_directory() . '/inc/customizer.php' );

and comment it out, like this:

//require( get_template_directory() . '/inc/customizer.php' );

This will remove all of the settings as well as the incline css. The only customizer settings that will be available will be the default settings set by WordPress core. Keep in mind, whichever route you choose, you will have to redo everything when I release an update as any changes you make will be over written.

Remove Customizer via a Child Theme

Now let’s go ahead and explore the safest way of removing WP-Forges’ customizer settings. This is also considered the “right” way. This is accomplished by using a child theme. You can use WP-Starter or you can create your own child theme. Either way is fine. Remember, you still nee to add the “if function_exists” we added above in order for this to work.

So open your child theme functions.php. The first thing we are going to do is remove the actual customizer we registered. Go ahead and add the following:

function remove_parent_customizer() {
    remove_action( 'customize_register', 'wpforge_customize_register' );
}
add_action( 'after_setup_theme', 'remove_parent_customizer', 9 );

All we did was add a function called “remove_parent_customizer” (you can call it whatever you want) and then we told it to remove the custom customizer that comes with WP-Forge. Now this will remove all of the settings but leave the default settings added by core WordPress. Niffty isn’t it? I think so.

However the inline css is still in the header. Now you can leave this if you want but if you want to start all over again from scratch we will need to write another function to remove it. So, with your child theme functions.php still open go ahead and add the following:

function remove_customizer_css() {
    remove_action('wp_head', 'wpforge_customize_css', 100);
}
add_action( 'after_setup_theme', 'remove_customizer_css', 9 );

Now the inline css should be gone and you can begin building the site you have always wanted.

So that my awesome community is how you remove the customizer settings and css that ships with WP-Forge. I highly recommend that you go the route and use a child theme. Remember if you have any ideas for snippets, please feel free to email me or leave a suggestion

11 thoughts on “Snippet: How to completely remove the Customizer settings of WP-Forge

  1. Hi Thomas!

    I really like WP Forge but I have a strange problem: I’m using a child theme with WP Forge and I noticed the customizer is not working. Whenever I change back to the parent theme – WP Forge – it works.

    With Dev Tools I noticed that theme-customizer.js is not loaded when using the child theme.

    Any ideas how I can make it work? I disabled all plugins. So it’s not a problem with that. I prefer not to add my own customizer, since you already provided one.

    Thanks!

    Andy

    • HI there,

      glad you like the theme. Could you be a little more specif when you state “the customizer isn’t working” please.

      Also, I see you posted this here instead of in the support forums, so I have to ask, did you follow this tutorial?

      Did you use your own child theme? Did you use WP-Starter?

  2. Hi Thomas!

    I posted here because Google brought me here, sorry! I can post my question over at the forum.

    Basically the child theme should be able to access the customizer of the parent theme and live preview should work, however, using WP Starter as the basis for the child theme, for some reason, it just doesn’t.

    I did a quick test: I created a child theme of 2016, activated it, same site, same plugins, and live preview works.

    I’m just trying to figure out why it’s not working with WP Forge. If I find the problem, I post about it in the forums.

    Thanks again for a great starter theme!

    Andy

    • Hey there,

      No need to post to the forum, I was just curious is all. I just like posts like this to be posted where everyone can see them.

      This is the first post where someone has stated that wp-starter wasn’t working as it should and the them has been out for almost a year.

      Whet did you download the themes from? Are you sure WP-Forge folder is called wp-forge and not wp-forge-master or something like that?

      Do you have a link and possibly the login so I can take a look? If so email me the info and I’ll take a look.

      Thanks again.

  3. Hi Thomas,

    The comment you just added to the snippet “Remove Open Sans and Use Your Favorite Google Font in WP-Forge” reminded me that in the meantime I had done something similar in my child theme to remove the customizer. Instead of what you wrote above, I added the following code to my functions.php file:

    /**
     * Disable the WP-Forge Theme Customizer
     * See http://themeawesome.com/themeawe/remove-customizer-settings/
     */
    function wpforge_customize_register() {
        return;
    }
    function wpforge_customize_css() {
        return;
    }

    Does this look ok?

    • Hey there,

      Yes sir, it works like a charm, great work again. Thanks for adding it for everyone to use.

      Now you should be able to add your own css and make the theme look exactly as you want. I will now update this post as well 😉 – Thanks again, I greatly appreciate your input.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.