236 posts
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Has been a member for 3-4 years
  • Bought between 1 and 9 items
  • Envato Studio (Microlancer) Beta Tester
GradaStudio says

Reviewer Said

Please, enqueue custom scripts/styles into your specific Theme page with conditionals, so that the JS/CSS doesn’t impact other areas of the theme.

here is my code for css and js

/*********** LOAD ALL REQUIRED SCRIPTS AND STYLES ***********/
function loadScripts() {
    if ( !is_admin() ) {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', get_template_directory_uri() .'/js/jquery-1.7.1.min.js', false, '1.6.2' );
        wp_enqueue_script( 'jquery' );
        wp_enqueue_script( 'top-menu', get_template_directory_uri() . '/js/menu.js', array( 'jquery' ) );

        wp_enqueue_script( 'scrolltopcontrol', get_template_directory_uri() .'/js/scrolltopcontrol.js' );
        wp_enqueue_script( 'jquery-tweet', get_template_directory_uri() .'/js/jquery.tweet.js', array( 'jquery' ) );
        wp_enqueue_script( 'jquery-jcarousel', get_template_directory_uri() .'/js/jquery.jcarousel.min.js', array( 'jquery' ) );
        wp_enqueue_script( 'slimbox2', get_template_directory_uri() .'/js/slimbox2.js' );
        wp_enqueue_script( 'jquery-validate', get_template_directory_uri() .'/js/jquery.validate.pack.js' );

        wp_enqueue_script( 'jcycle' , 'http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js', array( 'jquery' ) );
        wp_enqueue_script( 'nivo-slider', get_template_directory_uri() .'/js/jquery.nivo.slider.pack.js' );
        //wp_enqueue_script( 'jquery-contactable', get_template_directory_uri() .'/js/jquery.contacable.js' );

        wp_enqueue_script( 'my-custom-scripts', get_template_directory_uri() . '/js/custom.js', array( 'jquery', 'jcycle' ), '1.0' );
    }
}
add_action( 'init', 'loadScripts' ); //Load All Scripts

function loadExtraScripts() {
        if ( is_page_template( 'template-portfolio.php' ) ) {
            wp_enqueue_script('prettyPhoto',get_template_directory_uri().'/js/jquery.prettyPhoto.js',array( 'jquery' ) ); 
            wp_enqueue_script('filterable', get_template_directory_uri().'/js/filterable.js',array( 'jquery' ) ); 
        }
        if ( is_page_template( 'template-contact.php' ) ) {
            wp_enqueue_script('gmap-api','http://maps.google.com/maps/api/js?sensor=false',array( 'jquery' ) ); 
            wp_enqueue_script('gmap-min', get_template_directory_uri().'/js/gmap3.min.js',array( 'jquery' ) ); 
        }

}

if ( !is_admin() ) add_action( 'wp_print_scripts', 'loadExtraScripts' );

function al_front_styles(){
    wp_enqueue_style('reset-style',  get_stylesheet_directory_uri() . '/css/reset.css');
    wp_enqueue_style('theme-fonts',  get_stylesheet_directory_uri() . '/fonts/fonts.css');
     wp_enqueue_style('theme-skin',  get_stylesheet_directory_uri() . '/css/light.css');    

     if( is_page_template( 'template-portfolio.php' ) ) {
         wp_enqueue_style('prettyPhoto-style',  get_stylesheet_directory_uri() . '/css/prettyPhoto.css');
         wp_enqueue_style('filterable-style',  get_stylesheet_directory_uri() . '/css/filterable.css');
     }                
 }
if ( !is_admin() ) add_action('wp_enqueue_scripts', 'al_front_styles');

Dont know exactly what i need to change, need little help.

2566 posts Put a Donk On It
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Exclusive Author
  • Attended a Community Meetup
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 200 and 499 users
+5 more
ThemeProvince says

Why are you deregistering jQuery then registering it again?

3424 posts
  • Football Contest Participant/Runner-up
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Community Moderator
  • Bought between 100 and 499 items
  • Referred more than 2000 users
  • Has been a member for 4-5 years
+5 more
sevenspark Volunteer moderator says

Why are you deregistering jQuery then registering it again?

+1, definitely don’t do that. And if you do don’t set the version of jQuery 1.7.1 to ‘1.6.2’ ;)

A theme should never deregister the default jQuery library.

In the admin area, make sure you follow these best practices for keeping your JS only on your theme pages:

http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_scripts_only_on_plugin_pages
236 posts
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Has been a member for 3-4 years
  • Bought between 1 and 9 items
  • Envato Studio (Microlancer) Beta Tester
GradaStudio says

thanks for the response. so other than jquery thing above code is fine ??

should i check back end code ??

i used
add_action('admin_enqueue_scripts', 'al_admin_scripts');

here al_admin_scripts function enqueue scripts and styles

1081 posts
  • Forum Superstar
  • Most Wanted Bounty Winner
  • Envato Studio (Microlancer) Beta Tester
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Referred between 50 and 99 users
  • Europe
  • Has been a member for 3-4 years
  • Exclusive Author
+1 more
Smartik says

Use “wp_enqueue_style” to add all css files and only after that use “wp_enqueue_script”.

Cheers.

386 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Referred more than 2000 users
  • Bought between 500 and 999 items
  • Has been a member for 4-5 years
  • Exclusive Author
  • United States
WPExplorer says

Why do you have 2 functions to load scripts? I would consolidate them into 1 function.

Also consider loading them into the footer and not the header.

Also nivo-slider seems to be missing dependencies.

3424 posts
  • Football Contest Participant/Runner-up
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Community Moderator
  • Bought between 100 and 499 items
  • Referred more than 2000 users
  • Has been a member for 4-5 years
+5 more
sevenspark Volunteer moderator says

Also, save the get_stylesheet_directory_uri() result in a variable rather than running the function every time you need that value. No need to call it more than once per function.

386 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Referred more than 2000 users
  • Bought between 500 and 999 items
  • Has been a member for 4-5 years
  • Exclusive Author
  • United States
WPExplorer says

Also,

If you are using get_stylesheet_directory_uri() – remember if someone creates a child theme it will search for those css files within the child theme.

3424 posts
  • Football Contest Participant/Runner-up
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Community Moderator
  • Bought between 100 and 499 items
  • Referred more than 2000 users
  • Has been a member for 4-5 years
+5 more
sevenspark Volunteer moderator says

Also, If you are using get_stylesheet_directory_uri() – remember if someone creates a child theme it will search for those css files within the child theme.

Good point. You should be using get_template_directory_uri() for any resources included in your theme (seems you’re doing this for scripts but not stylesheets – it should be for both).

2566 posts Put a Donk On It
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Exclusive Author
  • Attended a Community Meetup
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Referred between 200 and 499 users
+5 more
ThemeProvince says


Also, If you are using get_stylesheet_directory_uri() – remember if someone creates a child theme it will search for those css files within the child theme.
Good point. You should be using get_template_directory_uri() for any resources included in your theme (seems you’re doing this for scripts but not stylesheets – it should be for both).

You should create a constant for this type of function. For example the top of functions.php should have the define function like this:

define("THEME_ROOT", get_template_directory_uri());
by
by
by
by
by
by