Bug in Responsive WordPress Themes: Single Post (single.php)

  • Gerry
    Gerry
    Newbie 61 points
    August 7, 2013 at 9:31 am

    In the code you have:

    /* =============================================================================
    LOAD PAGE TEMPLATE
    ========================================================================== */

    $GLOBALS[‘flag-single’] = 1;

    // ADD-ON PLAYER FILES ENCASE WE HAVE VIDEO
    wp_enqueue_script(‘video’, get_template_directory_uri().’/framework/player/mediaelement-and-player.min.js’);
    wp_enqueue_script(‘video’);

    wp_enqueue_style(‘video’, get_template_directory_uri().’/framework/player/mediaelementplayer.min.css’);
    wp_enqueue_style(‘video’);

    // ADD-ON SLIDER STYLES
    wp_enqueue_script(‘slider’, get_template_directory_uri().’/framework/slider/jquery.flexslider-min.js’);
    wp_enqueue_script(‘slider’);

    wp_enqueue_script(‘prettyphoto’, get_template_directory_uri().’/framework/slider/jquery.prettyPhoto.js’);
    wp_enqueue_script(‘prettyphoto’);

    wp_enqueue_style(‘slider’, get_template_directory_uri().’/framework/slider/flexslider.css’);
    wp_enqueue_style(‘slider’);

    wp_enqueue_style(‘prettyphoto’, get_template_directory_uri().’/framework/slider/prettyPhoto.css’);
    wp_enqueue_style(‘prettyphoto’);

    // UPDATE VIEW COUNTER
    $CORE->HITCOUNTER($post->ID);

    // ADD IN TOOLBOX FOR AUTHOR DATA
    add_action(‘hook_single_after’,array($CORE, ‘AUTHOR_TOOLBOX’) );

    which says if ‘x’ example wp_enqueue_script(‘slider’, get_template_directory_uri().’/framework/slider/jquery.flexslider-min.js’);
    wp_enqueue_script(‘slider’);

    then print in header the css and js for flexslider, but I have found that this is not working as intended, if there is no flex slider or outhes ie pretty phot the code is still printed in the header.

  • Richard Bonk
    Richard Bonk
    Super Guru 2,739 points
    August 7, 2013 at 10:22 am

    but I have found that this is not working as intended

    The code does exactly as intended. It loads the css and javascript in the header.

  • Gerry
    Gerry
    Newbie 61 points
    August 7, 2013 at 10:29 am

    Yes Richard it does, but should it not be calling the js and css files if only the items are being used on the page ie: video, slider etc. Or did I read the code wrong.

    Because the video call does not call video js and css if there is no video on the page?

  • Richard Bonk
    Richard Bonk
    Super Guru 2,739 points
    August 7, 2013 at 10:36 am

    No, it can’t as the scripts and style has to be loaded in head before the page is being processed – and thus it does not know whether the specific feature (e.g. video or slider) has been used or not.

  • Gerry
    Gerry
    Newbie 61 points
    August 7, 2013 at 10:53 am

    Just an idea then…. maybe the user of https://modernizr.com/ and https://yepnopejs.com/ could be looked at as it will create a better user experience, and also only load necessary files js and css for particular pages.

    Also with loading whats needed will result in faster page load times for both desktop and mobile.

  • Richard Bonk
    Richard Bonk
    Super Guru 2,739 points
    August 7, 2013 at 11:23 am

    Nice idea, but would require complete rework of the theme, which means many hours of work to just get saving of few bytes on some pages (as most pages will need the scripts anyway).
    Why not post it in the Feature Request Board?

  • Gerry
    Gerry
    Newbie 61 points
    August 7, 2013 at 11:27 am

    Can do 😯

  • Adam
    Adam
    Senior Member 142 points
    August 7, 2013 at 12:15 pm

    You may want to try this plugin or similar:
    https://wordpress.org/plugins/selective-loading/

  • Gerry
    Gerry
    Newbie 61 points
    August 7, 2013 at 12:32 pm

    Hey Adam… thanks for the plugin idea… and i think its great for certain uses like why call a video plugin if there is no video on the page.

    But it still does not stop the loading of unecessary js or css i think, i am going to try this baby out.

    Thanks

  • Adam
    Adam
    Senior Member 142 points
    August 7, 2013 at 12:53 pm

    There are some other plugins out there that do similar, and I THINK ones that let you fully manage all js and css that’s loaded per page/post, but at the moment I’m having trouble finding it.

  • Gerry
    Gerry
    Newbie 61 points
    August 7, 2013 at 1:24 pm

    Hey appreciate the help

  • Mark Fail
    Mark Fail
    Super Guru 13,013 points
    August 7, 2013 at 1:54 pm

    lol 🙂

Viewing 12 posts - 1 through 12 (of 12 total)

New Business Themes for WordPress 2020

Start your new website today!

View Business Themes