samtiria / nextgen-gallery

Automatically exported from code.google.com/p/nextgen-gallery
0 stars 0 forks source link

Conditional statment for NGG_SKIP_LOAD_SCRIPTS in functions.php #441

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, I am running NGG 1.8.4 on WP 3.2.1 and Thesis 1.8.2

I have inserted this code into the Thesis custom_functions.php, and the code 
outputs the expected echo statements, but doesn't properly load or not load the 
scripts. 

add_action('wp_head','ngg_scripts_new');
function ngg_scripts_new(){
    if (!is_page(array('gallery-test'))){define('NGG_SKIP_LOAD_SCRIPTS',true); 
        echo "No Scripts";
        }
    else {define('NGG_SKIP_LOAD_SCRIPTS',false); 
        echo "Scripts";
        }
}

Let me know if I should use a different hook, or what else might help to 
successfully run this from the custom_functions.php file.

Thanks.

Original issue reported on code.google.com by rs.testi...@gmail.com on 20 Nov 2011 at 3:08

GoogleCodeExporter commented 8 years ago
You need to ensure that the constant is definded, prior to the hook 
'template_redirect' as this load the final scripts:

add_action('template_redirect', array(&$this, 'load_scripts') );

Original comment by alex.cologne on 20 Nov 2011 at 4:05

GoogleCodeExporter commented 8 years ago
Here is the functioning version that I came up with.  
Note the hook to "wp" and the lack of use of "define" at all in the case of 
pages where scripts are needed.

add_action('wp','ngg_scripts_new');
function ngg_scripts_new(){
    if (is_page('4')){}
    else {define('NGG_SKIP_LOAD_SCRIPTS',TRUE);}
}

Original comment by rs.testi...@gmail.com on 21 Nov 2011 at 1:29