• Valentin

    (@valentinalisch)


    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 with id = 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

    http://wordpress.org/plugins/bj-lazy-load/

Viewing 7 replies - 1 through 7 (of 7 total)
  • thanks.
    I have use this code for IE detect for Internet Explorer.

    add this in theme’s functions.php

    <?php
    /*
     * Disable BJ Lazy Load for Internet Explorer browser
     */
    function BJLL_detect_ie()
    {
        if (isset($_SERVER['HTTP_USER_AGENT']) &&
        (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
            return true;
        else
            return false;
    }
    if (BJLL_detect_ie()){
    	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');
    }
    ?>

    I have tested with IE, Firefox & Chrome and it seems to work correctly

    remove blank line between those two

    add_action('wp_print_scripts','remove_BJLL_script');
    
    function remove_BJLL_filter(){

    it may cause errors.

    Plugin Author bjornjohansen

    (@bjornjohansen)

    Just as a note: Version 0.7.0 has a meta box on all posts/pages to skip BJ Lazy Load for that specific post/page. Also works with infinite scroll/AJAX loaded posts.

    Thread Starter Valentin

    (@valentinalisch)

    Thanks for the implementation.
    Would it be possible to implement it in the other way around as well?

    So in the general settings I choose not to use the plugin and then I’m able to activate it on a single page?
    That way I would not have to set a checkbox on every page if I want to use the plugin on just one page.

    Plugin Author bjornjohansen

    (@bjornjohansen)

    It would be much easier for you to disable all filtering on the BJ Lazy Load Options page and then just use the filter on the content for the specific page you want to use it on.

    If 1234 is the ID of the post/page you want to use BJ Lazy Load on:

    <?php
    
    add_filter( 'the_content', 'my_bjll_activation_filter', 20 );
    
    function my_bjll_activation_filter( $content ) {
    	if ( 1234 == get_the_ID() ) {
    		$content = apply_filters( 'bj_lazy_load_html', $content );
    	}
    
    	return $content;
    }

    Please be absolutely sure that you have set «Apply to content» to «no» before you do this. Otherwise your content will be filtered twice – and you don’t want that.

    Thread Starter Valentin

    (@valentinalisch)

    Yeah I know thank you.
    (I started this thread as you might have realized 😉 )

    Just would have been a lot nicer to have it integrated.

    I’ve checked the box telling it to skip lazy loading on a page which it’s completely ignoring.

    Could it be because my threshold is set to -1?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Solution] Disable BJLL on specific pages/specific browsers’ is closed to new replies.