Forums

How to output script only on frontpage? (3 posts)

  1. uspehovna
    Member
    Posted 10 months ago #

    I have next code:

    if ( !is_admin()) {
    		function register_my_js() {
    
    			wp_enqueue_script('my-js', get_bloginfo( 'template_directory' ).'/js/bg.js',array('jquery'), '1.0', true);
    
    		}
    		add_action('init', 'register_my_js');
    	}

    I used is_home and is_front_page conditions, but when i do this, my script doesn't include, without conditions script works but on all pages. And i need only on fron page, what should i do?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 10 months ago #

    function register_my_js() {
    	wp_enqueue_script('my-js', get_bloginfo( 'template_directory' ).'/js/bg.js',array('jquery'), '1.0', true);
    }
    if( is_home() || is_front_page() ) add_action('init', 'register_my_js');
  3. uspehovna
    Member
    Posted 10 months ago #

    Thanks, but anyway it doesnt't work. ((

Reply

You must log in to post.

About this Topic