WordPress.org

Forums

[resolved] Conditional Statements not working in functions.php (5 posts)

  1. AngelEyes
    Member
    Posted 3 years ago #

    I know that there are some things that you can do in your templates that effect the use of conditional statements. I have this function that loads my scripts in functions.php. These conditional statements have no effect. If I take the wp_register_script and enqueue out of the conditional statement it works fine. Its the conditional that is broken.

    Is there anything that I'm not noticing here? Is there something that is well documented as causing conditional statements to break that I should look for?

    /**
     *	Enqueue Scripts
     */
    
    if ( !function_exists('ScriptLoader') ) {
        function ScriptLoader() {
        	if (!is_admin()) {
    
    		wp_deregister_script( 'jquery' );
    		wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js', array(), '1.6.4', false );
    		wp_enqueue_script( 'jquery' );
    
    		if ( is_home() || is_archive() ) {
    
    			wp_register_script( 'easyslider', 'http://www.myurl.com/wp-content/etc/js/libs/easySlider1.5.js', array( 'jquery' ), '1.5', true );
    
    			wp_enqueue_script( 'easyslider' );
    
    			}
    		if ( is_page(77) ) {
    
    			wp_register_script( 'mail', 'http://www.myurl.com/wp-content/etc/js/mail.js', array( 'jquery' ), '1.0', true );
    
    			wp_enqueue_script( 'mailchimp' );
    
    			}
    
    		}
    
        }
    
    }
    add_action('init', 'ScriptLoader');
  2. AngelEyes
    Member
    Posted 3 years ago #

    i know using Query_posts outside of your main loop can screw up conditional statements but I dont think I'm doing this anywhere. I definitely have a handful of loops outside my main loop but im mainly using get_posts and maybe one WP_Query

  3. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    http://wordpress.org/support/topic/wp_enqueue_script-with-add_actioninit?replies=3

    Should be helpful.... I believe your conditionals don't pick up, because init is fired too soon.

  4. AngelEyes
    Member
    Posted 3 years ago #

    ah! lovely. Thanks for that tip Rev. Voodoo. That sorted me right out!

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    Good stuff!!

Topic Closed

This topic has been closed to new replies.

About this Topic