236 posts
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
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.

2587 posts Put a Donk On It
  • Elite Author: Sold more than $75,000 on Envato Market
  • Sells items exclusively on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has sold $250,000+ on Envato Market
+10 more
ThemeProvince says

Why are you deregistering jQuery then registering it again?

3495 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark 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
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
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

1272 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
Smartik says

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

Cheers.

401 posts
  • Located in United States
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Made it to the Authors' Hall of Fame
+4 more
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.

3495 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark 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.

401 posts
  • Located in United States
  • Power Elite Author: Sold more than $1M on Envato Market
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Made it to the Authors' Hall of Fame
+4 more
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.

3495 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark 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).

2587 posts Put a Donk On It
  • Elite Author: Sold more than $75,000 on Envato Market
  • Sells items exclusively on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has sold $250,000+ on Envato Market
+10 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());

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by