Support » Plugin: Nextend Social Login and Register » Remove CSS & JS from unnecessary pages

  • Resolved Mehdi24

    (@mehdi24)


    Dear,
    I use social login in just two pages and should remove css and js codes from other pages and posts. How can i do that?
    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Laszlo

    (@laszloszalvak)

    Hi @mehdi24

    I am sorry, but you can not remove our CSS and JavaScript, as we can not know in advance what pages the social buttons will be displayed on, since the social buttons can not only be published with our shortcode and PHP code, but with HTML as well. And our style and JavaScript codes need to work in those cases, too.

    Best regards,
    Laszlo.

    Thread Starter Mehdi24

    (@mehdi24)

    Thanks @laszloszalvak
    I included printed CSS & JS codes using “if (is_page())” in pages i need and remove “template-parts\style.css” & “js\nsl.js” files from plugin directory.
    It seems good and works fine but is there a better way to remove css js codes rather than removing files? Some plugins support “wp_enqueue_scripts” to disable code printing.
    Thanks

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @mehdi24

    If you really want our CSS and JavaScript codes not being called in on certain pages, then on the frontend they are hooked to the: wp_head and wp_print_footer_scripts actions.
    So with a remove_action function of WordPress:

    you could unhook them, e.g. with a condition that unhooks our functions on every page except the one with the ID where you display your social buttons.

    Please note that, we can not provide support for custom coding and problems caused by custom codes, BUT Here is a very basic example for that:

    $pageID = get_the_ID();
        if ($pageID !== 61) {
            remove_action('wp_head', 'NextendSocialLogin::styles', 100);
            remove_action('wp_print_footer_scripts', 'NextendSocialLogin::scripts', 100);
        }

    In this case our styles and scripts would be only called in on the page with the ID 61.

    Best regards,
    Laszlo.

    Thread Starter Mehdi24

    (@mehdi24)

    @laszloszalvak
    Thanks. I couldnt use your code directly in theme functions.php file. So used them in 2 function:

    function remove_nextend_css() {
        if(!is_page(array(22,23))):
            remove_action('wp_head', 'NextendSocialLogin::styles', 100);
        endif;
    }
    add_action( 'wp_head', 'remove_nextend_css' );
    
    function remove_nextend_js() {
       if(!is_page(array(22,23))):
            remove_action('wp_print_footer_scripts', 'NextendSocialLogin::scripts', 100);
        endif;
    }
    add_action( 'wp_print_footer_scripts', 'remove_nextend_js' );

    Code works fine. Is this correct and optimize?

    • This reply was modified 1 year, 4 months ago by Mehdi24.
    • This reply was modified 1 year, 4 months ago by Mehdi24.
    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @mehdi24

    Yes, it seems to be fine.

    I am glad you managed to make it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Remove CSS & JS from unnecessary pages’ is closed to new replies.