[Solution] Disable BJLL on specific pages/specific browsers
-
Hey there,
the following code examples show solutions if you want to disable the BJLL plugin on specific wordpress pages or if you want the plugin only to be active on one page.All of the code posted below has to be inside your theme’s
functions.php
file.- Activate BJLL only on the blog posts page
if(!is_home()){ function remove_BJLL_script(){ wp_deregister_script('BJLL'); } add_action('wp_print_scripts','remove_BJLL_script'); function remove_BJLL_filter(){ $bjll = BJLL::singleton(); remove_filter('the_content',array($bjll, 'filter'),200); } add_filter('wp','remove_BJLL_filter'); }
Functions checks whether the blog page is displayed or not.
If it isn’t the BJLL files will be unloaded.
Else they stay in your source code.- Activate BJLL on all pages but one
$current_id = get_the_id(); if($current_id == 0){ function remove_BJLL_script(){ wp_deregister_script('BJLL'); } add_action('wp_print_scripts','remove_BJLL_script'); function remove_BJLL_filter(){ $bjll = BJLL::singleton(); remove_filter('the_content',array($bjll, 'filter'),200); } add_filter('wp','remove_BJLL_filter'); }
Using this code BJLL files will be included on every page except for the page with
id = 0
.- Other possibilities
This method of excluding the plugin files offers unlimited possibilities.
Detect a specific browser, exclude the files on mobile devices, etc.- ——————————
PROBLEM
- ——————————
If you’re using an AJAX plugin to load your pages dynamically and don’t have hard reloads this method of excluding the plugin files won’t work.
There’s one other solution it requires modifying the plugin files though.
You have to enclose the code lines
73-81
in whatever condition you want to have.
The following example includes the plugin only on the page withid = 0
//USER MOD $page_id = get_the_id(); if($page_id == 67){ if ( $options->get( 'filter_content' ) == 'yes' ) { add_filter( 'the_content', array( $this, 'filter' ), 200 ); } if ( $options->get( 'filter_post_thumbnails' ) == 'yes' ) { add_filter( 'post_thumbnail_html', array( $this, 'filter' ), 200 ); } if ( $options->get( 'filter_gravatars' ) == 'yes' ) { add_filter( 'get_avatar', array( $this, 'filter' ), 200 ); } }
Regards,
Valentin
- The topic ‘[Solution] Disable BJLL on specific pages/specific browsers’ is closed to new replies.