Published on Jun 23, 2019
Conditionally targeting all Pages that use a Oxygen Template
Sridhar Katakam
In a PSD > WP project that I recently completed, the requirement was to implement Tocbot on all Pages that use a specific Oxygen Template.
With a traditional theme-based approach we can is_page_template( 'page-example.php')
add_action( 'wp_enqueue_scripts', 'custom_enqueue_files' );
/**
* Loads <list assets here>.
*/
function custom_enqueue_files() {
if ( is_page_template( 'page-example.php' ) ) {
wp_enqueue_script( 'tocbot', plugin_dir_url( __FILE__ ) . 'assets/js/tocbot.min.js', array(), '4.3.1', true );
}
}
This is not possible with Oxygen but we can do a little out of the box thinking and achieve it like so:
- add a body class to the Pages that use the Oxygen Template
- loop through all the body classes, look for the above body class and then enqueue the script.
This members-only tutorial provides the details to implement the above.
Step 1
Edit the Oxygen Template.
Add a Code Block.
PHP:
This is a premium members-only content.
To view the rest of the content, please sign up for membership ($47/month or $599 one-time).
Already a member? Log in below or here.