Conditional statements in functions file
-
Hello,
In the theme i am developing (using wordpress and the genesis framework), i have a number of conditional statements in the functions file to determine what content appears on which pages, for example:/* Add directory to directory page*/ function include_storefinder(){ if ( is_page('a-z-directory') ){ require(CHILD_DIR.'/storefinder.php'); remove_action('genesis_post_content', 'genesis_do_post_content'); } } add_action( 'genesis_after_post_title', 'include_storefinder' );
However, when i try to use the same conditional statement to load a javascript only on this page, it stops the script from loading at all; I can only have it on all pages (which increases load time), or none.
/* Register directory.js*/ function directoryinit() { if ( is_admin() ) return; /* Conditional for a-z directory page won't work */ wp_register_script('shopDirectory', get_stylesheet_directory_uri(). '/js/storedirectory.js', array('jquery') ); wp_enqueue_script('shopDirectory'); wp_localize_script( 'shopDirectory', 'localnames', localize_vars()); } add_action('init', 'directoryinit');
I know some of my code is genesis-specific, but the underlying problem of getting a script to load just on the page(s) where it is required is general to wordpress. Thanks in advance for any help.
- The topic ‘Conditional statements in functions file’ is closed to new replies.