Loading Assets in Isolated Page Templates

The isolation template does not load the styles and scripts embedded by the themes or other plugins. This ensures that the styles and scripts are isolated and loads minimal assets on the page. However, there may be cases where you’d want to use additional scripts/styles alongside your Supercharged forms in isolation mode.

If you know the handle of your scripts or styles, you can white list it for the isolated template using a simple filter. Once added to the whitelist, it will be loaded in the head or footer like normal.

Filters

To whitelist a stylesheet that that’s already added by the name of my-styles and my-other-styles. We can use the following code with the filter gf_supercharge_isolated_styles:

function gf_supercharge_isolated_styles_whitelist( $styles ) {

    $my_styles = array(
        "my-styles",
        "my-other-styles"
    );

    return array_merge( $styles, $my_styles );
}

add_filter( "gf_supercharge_isolated_styles", "gf_supercharge_isolated_styles_whitelist", 10 );

To whitelist a script, the same can be done with the scripts whitelist filter gf_supercharge_isolated_scripts

function gf_supercharge_isolated_scripts_whitelist( $scripts ) {

    $my_scripts = array(
        "my-scripts",
        "my-other-scripts"
    );

    return array_merge( $scripts, $my_scripts );
}

add_filter( "gf_supercharge_isolated_scripts", "gf_supercharge_isolated_scripts_whitelist", 10 );

Action

To perform additional actions, you may use the action hook gf_supercharge_isolated_footer. This hook is fired right before the footer scripts are enqueued. This action can be handy, specially as a substitute for when you want to fire something that was added to the wp_footer action, which doesn’t get fired on this template.

Share your thoughts. We're all ears.

Your email address will not be published. Required fields are marked *