Easy WordPress Drop Downs using CSS
The snippet will help you creating an easy WordPress drop downs using CSS.
1 2 3 4 5 6 7 8 9 |
ul.menu, ul.menu li { float: left; } ul.menu li { position: relative; margin: 0 15px; list-style: none; } .sub-menu { position: absolute; float: none; width: 100px; padding: 0; left: 0; } .sub-menu li { display:none; margin: 0; padding: 0; } ul.menu li:hover li { float: none; display:block; clear: both; } |
Source: AmberWeinberg
Redirecting your homepage to the first post
Simply paste the code to your site’s homepage file (mainly it is index.php file) and you will be able to redirect your homepage to the first post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php /* home.php (Blog Home Page): Redirect To First Post */ if (have_posts()) { while (have_posts()) { the_post(); wp_redirect(get_permalink()); } } ?> |
Source: Ashton Sanders
How to automatically add a search field to your navigation menu
On copying the code to your theme’s functions.php file you will be able to add a search filed automatically to your navigation menu.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
add_filter('wp_nav_menu_items','add_search_box', 10, 2); function add_search_box($items, $args) { ob_start(); get_search_form(); $searchform = ob_get_contents(); ob_end_clean(); $items .= '<li>' . $searchform . '</li>'; return $items; } |
Source: Ronald
Removing the “read more” jump
Adding the shortcode into your functions.php file will remove the “read more” link from your blog which will automatically takes you to the article page.
1 2 3 4 5 6 7 |
function wdc_no_more_jumping($post) { return '<a href="'.get_permalink($post->ID).'" class="read-more">'.'Continue Reading'.'</a>'; } add_filter('excerpt_more', 'wdc_no_more_jumping'); |
Source: Alex Denning
Redirect feeds to a single format
Adding the following shortcode to your .htaccess file will let you direct all your feeds to a single format.
1 2 3 4 5 6 7 |
<IfModule mod_alias.c> RedirectMatch 301 /feed/(atom|rdf|rss|rss2)/?$ http://example.com/feed/ RedirectMatch 301 /comments/feed/(atom|rdf|rss|rss2)/?$ http://example.com/comments/feed/ </IfModule> |
Source: Digging into WordPress
How to have a simpler WordPress login url
Adding the following code to your .htaccess file will let you have the simpler WordPress login url.
1 |
RewriteRule ^login$ http://website.com/wp-login.php [NC,L] |
Source: Kevin Chard
WordPress is_child() and is_ancestor()
To use the following snippet, simply add it in your theme’s functions.php template.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
// Check if page is direct child function is_child($page_id) { global $post; if( is_page() && ($post->post_parent == $page_id) ) { return true; } else { return false; } } // Check if page is an ancestor function is_ancestor($post_id) { global $wp_query; $ancestors = $wp_query->post->ancestors; if ( in_array($post_id, $ancestors) ) { return true; } else { return false; } } |
Source: CodeByte
WP – Roles and Capabilities
The snippet will let you define different roles and capabilities.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
[edit_post] => "edit_{$capability_type}" [read_post] => "read_{$capability_type}" [delete_post] => "delete_{$capability_type}" [edit_posts] => "edit_{$capability_type}s" [edit_others_posts] => "edit_others_{$capability_type}s" [publish_posts] => "publish_{$capability_type}s" [read_private_posts] => "read_private_{$capability_type}s" [delete_posts] => "delete_{$capability_type}s" [delete_private_posts] => "delete_private_{$capability_type}s" [delete_published_posts] => "delete_published_{$capability_type}s" [delete_others_posts] => "delete_others_{$capability_type}s" [edit_private_posts] => "edit_private_{$capability_type}s" [edit_published_posts] => "edit_published_{$capability_type}s" edit_members read_members delete_members edit_memberss edit_others_memberss publish_memberss read_private_memberss delete_memberss delete_private_memberss delete_published_memberss delete_others_memberss edit_private_memberss edit_published_memberss |
Source: Snipplr
Clear out jquery to prevent conflicts
The snippet will let you either link a script with a handle previously registered using the wp_register_script() function, or provide this function with all the parameters necessary to link a script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
/* * WordPress Sample function and action * for loading scripts in themes */ // Let's hook in our function with the javascript files with the wp_enqueue_scripts hook add_action( 'wp_enqueue_scripts', 'wpcandy_load_javascript_files' ); // Register some javascript files, because we love javascript files. Enqueue a couple as well function wpcandy_load_javascript_files() { wp_deregister_script( 'jquery'); wp_register_script( 'jquery', get_template_directory_uri().'/js/jquery-1.8.2.min.js', array(), '1.8.2', false ); wp_enqueue_script('jquery'); wp_register_script( 'jquery.flexslider', get_template_directory_uri().'/js/jquery.flexslider.js', array('jquery'), '1.7', false ); wp_enqueue_script('jquery.flexslider'); } |
Source: WordPress Codex
Photo Credit: Flickr/hackNY.org