Easy WordPress Drop Downs using CSS
The following WordPress snippets will let you use easily WordPress drop downs using CSS.
1 2 3 4 5 6 7 8 9 10 11 |
The snippet will help you creating an easy WordPress drop downs using CSS. 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
Change footer-text in WP Admin
Using the WordPress Snippets will change the text in the bottom of the WP admin pages.
1 2 3 4 5 6 7 8 9 10 11 |
<?php function remove_footer_admin () { echo 'My footer text. Thank you <a href="http://wordpress.org">Wordpress</a> for giving me this filter.'; } add_filter('admin_footer_text', 'remove_footer_admin'); ?> |
Reduce spam by using .htaccess
Adding the following shortcode will let you reduce spam on your WordPress blog by using .htaccess. Simply paste the following lines into your .htaccess file but also make a note that you do make a backup of your .htaccess file before editing it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_METHOD} POST RewriteCond %{REQUEST_URI} .wp-comments-post\.php* RewriteCond %{HTTP_REFERER} !.*yourdomainname.* [OR] RewriteCond %{HTTP_USER_AGENT} ^$ RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L] </IfModule> |
Source: AllGuru.net
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
Include Future Posts in RSS Feed
Adding the snippet to your theme’s functions.php file will let you appear your future posts in your RSS feed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php /* Include published and future posts in rss feed. */ function FuturePostsFeed($query) { if ($query->is_feed) { $query->set('post_status','publish,future'); } return $query; } add_filter('pre_get_posts','FuturePostsFeed'); ?> |
Display a thumbnail of any website
Simply paste the code below into your functions.php file.
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 |
function gk_snap($atts, $content = null) { extract(shortcode_atts(array( "snap" => 'http://s.wordpress.com/mshots/v1/', "url" => 'http://www.geekeries.fr', "alt" => 'Mon image', "w" => '400', // largeur "h" => '300' // hauteur ), $atts)); $img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>'; return $img; } add_shortcode("snap", "gk_snap");unction gk_snap($atts, $content = null) { extract(shortcode_atts(array( "snap" => 'http://s.wordpress.com/mshots/v1/', "url" => 'http://www.geekeries.fr', "alt" => 'Mon image', "w" => '400', // largeur "h" => '300' // hauteur ), $atts)); $img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>'; return $img; } add_shortcode("snap", "gk_snap"); Once done, you can use the snap shortcode: [snap url="http://www.geekeries.fr/publicites/" alt="Ma description" w="400" h="300"] |
Source: Geekeries.fr
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
Remove meta-boxes
Using this snippet, you can remove the meta-boxes you don’t use.
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 |
<?php function remove_meta_boxes() { # Removes meta from Posts # remove_meta_box('postcustom','post','normal'); remove_meta_box('trackbacksdiv','post','normal'); remove_meta_box('commentstatusdiv','post','normal'); remove_meta_box('commentsdiv','post','normal'); # Removes meta from pages # remove_meta_box('postcustom','page','normal'); remove_meta_box('trackbacksdiv','page','normal'); remove_meta_box('commentstatusdiv','page','normal'); remove_meta_box('commentsdiv','page','normal'); } add_action('admin_init','remove_meta_boxes'); ?> |
Remove Gallery Settings
Gallery setting often make you irritated. The following snippet will simply remove all the gallery settings from the media upload section. All you have to do is simple add the code in your functions.php file.
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 |
<?php add_action( 'admin_head_media_upload_gallery_form', 'mfields_remove_gallery_setting_div' ); if( !function_exists( 'mfields_remove_gallery_setting_div' ) ) { function mfields_remove_gallery_setting_div() { print ' <style type="text/css"> #gallery-settings *{ display:none; } </style>'; } } ?> |
How to change WordPress editor font
Adding the following shortcode to your functions.php file will let you change the default WordPress editor font.
1 2 3 4 5 6 7 8 9 |
add_action( 'admin_head-post.php', 'devpress_fix_html_editor_font' ); add_action( 'admin_head-post-new.php', 'devpress_fix_html_editor_font' ); function devpress_fix_html_editor_font() { ?> <style type="text/css">#editorcontainer #content, #wp_mce_fullscreen { font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif; }</style> <?php } |
Source: DevPress