Enable and Disable Wp plugin / Custom styles and scripts per page
-
https://www.ads-software.com/plugins/wp-asset-manager/
A wordpress plugin that deactivates individual or all wp plugin styles and scripts per page to decrease load time. Please leave a review or suggested improvements and spread the word!
Common uses
- Contact Form 7 – CF7 will load its stylesheet and script into everypage, this plugin will restrict it to load into pages you need it for.
- Prevent jQuery loading into every page.
- Add/remove custom Stylesheets per page.
- Add/remove custom JS per page.
Code
Add the following code to your themes header and footerheader.php
<?php wp_reset_query(); global $post; $styles_query = get_post_meta( $post->ID, '_active_styles', true ); $styles_array = unserialize($styles_query); ?> <?php if (!empty($styles_array[0])) { foreach($styles_array as $style): ?> <link rel="stylesheet" href="<?php echo $style; ?>"> <?php endforeach; } ?>
footer.php
<?php wp_reset_query(); global $post; $scripts_query = get_post_meta( $post->ID, '_active_scripts', true ); $scripts_array = unserialize($scripts_query); ?> <?php if (!empty($scripts_array[0])) { foreach($scripts_array as $script): ?> <script src="<?php echo $script; ?>"></script> <?php endforeach; } ?>
https://www.twitter.com/WPAssetManager
Screenshots
- Custom Styles
https://www.johnburns87.com/wp-content/uploads/2014/04/custom-styles.png - Custom Scripts
https://www.johnburns87.com/wp-content/uploads/2014/04/custom-scripts.png - Disabling Plugin or Custom styles and scripts in a page/post
https://www.johnburns87.com/wp-content/uploads/2014/04/post-example.png
- The topic ‘Enable and Disable Wp plugin / Custom styles and scripts per page’ is closed to new replies.