megwoo
6/24/2015 - 5:19 AM

functions.php, custom.js, add/remove scripts, add link, admin logo, google analytics

functions.php, custom.js, add/remove scripts, add link, admin logo, google analytics

// adding custom jquery & css
function add_scripts() {
	wp_enqueue_style( 'style-name', get_stylesheet_uri() );
	wp_enqueue_script('custom-script',get_stylesheet_directory_uri() . '/js/custom.js', array( 'jquery' ));
	wp_enqueue_script('lettering-script',get_stylesheet_directory_uri() . '/js/jquery.lettering.js', array( 'jquery' ));
}
add_action( 'wp_enqueue_scripts', 'add_scripts' );

note, when using jQuery on WordPress, must form like this:
jQuery(document).ready(function($) {

  // test
  $('.page').css('background-color', 'red');
  
});


// add outside links to header
function add_links() {
  echo '<link rel="stylesheet" type="text/css" href="https://cloud.typography.com/6778734/7832972/css/fonts.css" />';
}
add_action('wp_head', 'add_links');

// add google analytics	
function init_analytics() {
	$analytics = "<script>
		(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
		(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
		m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
		})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
		
		ga('create', 'UA-99039081-1', 'auto');
		ga('send', 'pageview');
		</script>";
	
	echo "\n" . $analytics;
}
if (!is_admin()) {
	add_action('wp_footer', 'init_analytics', 35);
}

// add custom logo to admin login
function my_login_logo() {
    echo '<style type="text/css">#login h1 a, .login h1 a {background-image: url(' . get_stylesheet_directory_uri() . '/images/more-admin-logo.png); background-size: 200px; width: 200px; height: 49px;}</style>';
}
add_action( 'login_enqueue_scripts', 'my_login_logo' );


// remove script from parent theme
	function remove_scripts() {
		wp_deregister_script('retina'); // note, the file is called retina.js
	}
	add_action( 'wp_enqueue_scripts', 'remove_scripts', 100 );
	
	

// load css into the admin pages (wysiwyg)
function add_admin_scripts() {
    wp_enqueue_style( 'admin-css', get_stylesheet_directory_uri() . '/css/admin.css' ); 
}
add_action( 'admin_enqueue_scripts', 'add_admin_scripts' );
 

// load css into the login page
function add_login_scripts() {
    wp_enqueue_style( 'login-css', get_stylesheet_directory_uri() . '/css/login.css' ); 
}
add_action( 'login_enqueue_scripts', 'add_login_scripts' );
 
?>