if (!is_admin()) { wp_deregister_script(’jquery’); wp_register_script(’jquery’, ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false); wp_enqueue_script(’jquery’); wp_register_script(’hoverIntent’, get_bloginfo(’template_directory’) . ‘/js/hoverIntent.js’, null, null, false); wp_enqueue_script(’hoverIntent’); wp_register_script(’superfish’, get_bloginfo(’template_directory’) . ‘/js/superfish.js’, null, null, false); wp_enqueue_script(’superfish’); wp_register_script(’slider’, get_bloginfo(’template_directory’) . ‘/js/slider.js’, null, null, false); wp_register_script(’cycle’, get_bloginfo(’template_directory’) . ‘/js/jquery.cycle.js’, null, null, false); } function pp_conditional_script_loading() { if ( is_home() || is_category(’900’) || is_page (’page-slug’ ) || is_post_type_archive(’post_type’)… Continue reading Registering/Enqueing Scripts in functions.php
Tag: functions.php
Post Type rewrite rules
Nest a page under a post type archive: function my_rewrite_rules_array( $rules ) { $rules = array_merge( array( ‘post-type/pagename/?$’ => ‘index.php?pagename=post-type/pagename’, ), $rules ); return $rules; } add_filter( ‘rewrite_rules_array’, ‘my_rewrite_rules_array’ ); Nest a second post type under a main post type: function my_rewrite_rules( $rules ) { $newrules = array(); $newrules[’^.*/second-post-type-slug/([^/]+)$’] = ‘index.php?your_post_type=$matches[1]&post_type=your_post_type’; return… Continue reading Post Type rewrite rules
Hacks to Enhance WP Search Engine
Remove the “read more” jump
On WordPress blogs, when you click on a “Read more” link, it automatically drops to the point in the article you theoretically just got to the end of. If you don’t really like that jump, simply paste the following code into your functions.php file to get rid of it. function wdc_no_more_jumping($post) { return ‘<a… Continue reading Remove the “read more” jump
Prevent automatic image compression
By default, WordPress compress jpg images when you upload them to your blog. This is useful because it saves bandwidth and loading time, but sometimes you may prefer to have full quality images (For example, if you’re a photographer using WordPress to showcase your work). Paste the code below into your functions.php file to remove… Continue reading Prevent automatic image compression
Automatically add classes to links generated by next_posts_link and previous_posts_link
add_filter(’next_posts_link_attributes’, ‘posts_link_attributes’); add_filter(’previous_posts_link_attributes’, ‘posts_link_attributes’); function posts_link_attributes() { return ‘class="myclass"’; }
Remove Microsoft Word HTML tags
The following function takes some nightmarish Word HTML and return a clean HTML output that you can use safely on the web. function cleanHTML($html) { $html = ereg_replace("<(/)?(font|span|del|ins)[^>]*>","",$html); $html = ereg_replace("<([^>]*)(class|lang|style|size|face)=("[^"]*"|'[^’]*’|[^>]+)([^>]*)>","<\1>",$html); $html = ereg_replace("<([^>]*)(class|lang|style|size|face)=("[^"]*"|’[^’]*’|[^>]+)([^>]*)>","<\1>",$html); return $html }
Shortcode for TTF Titles
function the_ttftext_shortcode( $atts ) { extract( shortcode_atts( array( ‘text’ => ”, ‘echo’ => false, ‘style’ => ”, ‘overrides’ => ”, ), $atts ) ); return the_ttftext (esc_attr($text), false, esc_attr($style), esc_attr($overrides)); } add_shortcode(’ttf_text’, ‘the_ttftext_shortcode’); [ttf_text text=”Hello World!” style=”basic”]
Improved Excerpt
function improved_trim_excerpt( $text ) { if ( ” == $text ) { $permalink = get_permalink(); // my addition $text = get_the_content( ” ); $text = strip_shortcodes( $text ); $text = apply_filters( ‘the_content’, $text ); $text = preg_replace( ‘@<script[^>]*?> . *?</script>@si’, ”, $text ); $text = str_replace( ‘]]>’, ‘]]>’, $text ); $text = strip_tags( $text, ‘<b><em><i><p><strong><sub><sup><a>’… Continue reading Improved Excerpt
Exclude category from feed
Add to functions.php function myFeedExcluder($query) { if ($query->is_feed) { $query->set(’cat’,’-6’); } return $query; } add_filter(’pre_get_posts’,’myFeedExcluder’);
Custom Taxonomies
Add to functions.php: add_action( ‘init’, ‘create_my_taxonomies’, 0 ); function create_my_taxonomies() { register_taxonomy( ‘ingredients’, ‘post’, array( ‘hierarchical’ => false, ‘label’ => ‘Ingredients’, ‘query_var’ => true, ‘rewrite’ => true ) ); }