Various Functions
How to include javascript or jQuery:
This script loads all javascript and jQuery so that they don’t conflict with each other. You don’t have to include those scripts tags in the footer or header anymore. It is all done here. You can add more by copying and pasting more where it says. You just have to change the path to whatever the new file is and the two terms have to match, but can be anything.
// Enqueueing all the java script in a no conflict mode function ineedmyjava() { if (!is_admin()) { wp_deregister_script('jquery'); wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', false, '1.10.2', true); wp_enqueue_script('jquery'); // Custom Theme scripts... wp_register_script( 'custom', get_bloginfo('template_directory') . '/js/custom.js', array('jquery') ); wp_enqueue_script('custom'); // Homepage slider 'flexslider' scripts... wp_register_script( 'flexslider', get_bloginfo('template_directory') . '/js/flexslider.js', array('jquery') ); wp_enqueue_script('flexslider'); // Add more // between here } } add_action('wp_enqueue_scripts', 'ineedmyjava');
Register Nav menus:
register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) );
Custom Post Types:
/* Custom Post Types */ add_action('init', 'js_custom_init'); function js_custom_init() { // Register the Homepage Slides $labels = array( 'name' => _x('Slides', 'post type general name'), 'singular_name' => _x('Slide', 'post type singular name'), 'add_new' => _x('Add New', 'Slide'), 'add_new_item' => __('Add New Slide'), 'edit_item' => __('Edit Slides'), 'new_item' => __('New Slide'), 'view_item' => __('View Slides'), 'search_items' => __('Search Slides'), 'not_found' => __('No Slides found'), 'not_found_in_trash' => __('No Slides found in Trash'), 'parent_item_colon' => '', 'menu_name' => 'Slides' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => false, 'hierarchical' => false, // 'false' acts like posts 'true' acts like pages 'menu_position' => 20, 'supports' => array('title','editor','custom-fields','thumbnail'), ); register_post_type('slides',$args); // name used in query // Add more between here // and here } // close custom post type
Custom Taxonomies:
Line 9 – Name your taxonomy, and tell it which Custom Post Type to attach it to.
Line 17 – you can name a custom slug/url
/* ############################################## Custom Taxonomies */ add_action( 'init', 'build_taxonomies', 0 ); function build_taxonomies() { // cusotm tax register_taxonomy( 'custom_taxonomy', 'custom_post_type', array( 'hierarchical' => true, // true = acts like categories false = acts like tags 'label' => 'Organization Type', 'query_var' => true, 'rewrite' => true , 'show_admin_column' => true, 'public' => true, 'rewrite' => array( 'slug' => 'custom-taxonomy' ), '_builtin' => true ) ); } // End build taxonomies
Adding Custom Image Sizes:
// add additional image sizes //200 pixels wide (and unlimited height) add_image_size( 'recipe', 200, 9999 ); //400px wide 400px tall (hard crop mode) add_image_size( 'homepage', 400, 400, true ); //500px wide 500px tall (soft proportional crop) add_image_size( 'people', 500, 500 ); //600px wide 600px tall (hard crop from left and top) add_image_size( 'animals', 600, 600, array( 'left', 'top' ) ); //800px wide 800px tall (hard crop from middle and middle) add_image_size( 'biganimals', 600, 600, array( 'center', 'center' ) ); // x_crop_position accepts 'left' 'center', or 'right' // y_crop_position accepts 'top', 'center', or 'bottom' // How to use in your template pages: /* if ( has_post_thumbnail() ) { the_post_thumbnail( 'your-custom-size' ); } */
Featured Images:
to use featured images, you must have this in the functions file:
add_theme_support( 'post-thumbnails' );
Login Logo and Link:
/*------------------------------------- Custom client login, link and title. ---------------------------------------*/ function my_login_logo() { ?> <style type="text/css"> body.login div#login h1 a { background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/images/login-logo.png); background-size: 327px 67px; width: 327px; height: 67px; } </style> <?php } add_action( 'login_enqueue_scripts', 'my_login_logo' ); // Change Link function loginpage_custom_link() { return the_permalink(); } add_filter('login_headerurl','loginpage_custom_link');