#WordPress Snippets
Explore tagged Tumblr posts
iamzachreed · 14 years ago
Text
5 Useful WordPress Functions For Functions.php!
Lately, I have been diving into a few awesome WordPress projects that involve some very specific customizations and queries. I'm going to make a mini post series this week and next that involve some helpful code that wasn't easy to find around the web that has helped me do a lot of these customizations!
I will start out this mini post series with some helpful function.php snippets that are not always easy to find. These are all some functions that would go in the functions.php WordPress theme file. Hopefully these help you and save you some time searching around the web! Enjoy! :)
1. Only allow specific tags in WordPress comments
// only allow <strong>, <em>, pre, code, and <a href=""> tags add_action('init', 'my_html_tags_code', 10); function my_html_tags_code() { define('CUSTOM_TAGS', true); global $allowedposttags, $allowedtags; $allowedposttags = array( 'strong' => array(), 'em' => array(), 'pre' => array(), 'code' => array(), 'a' => array( 'href' => array (), 'title' => array () ) ); $allowedtags = array( 'strong' => array(), 'em' => array(), 'pre' => array(), 'code' => array(), 'a' => array( 'href' => array (), 'title' => array () ) ); }
2. Detect the browser or device being used and add a class to "Body"
// Add - Browser Detection Body Class add_filter('body_class','lh_browser_body_class'); function lh_browser_body_class($classes) { global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone; if($is_lynx) $classes[] = 'lynx'; elseif($is_gecko) $classes[] = 'gecko'; elseif($is_opera) $classes[] = 'opera'; elseif($is_NS4) $classes[] = 'ns4'; elseif($is_safari) $classes[] = 'safari'; elseif($is_chrome) $classes[] = 'chrome'; elseif($is_IE) $classes[] = 'ie'; else $classes[] = 'unknown'; if($is_iphone) $classes[] = 'iphone'; return $classes; }
3. Make WordPress automated emails a custom "from" email other than the default.
// Custom "from" email function res_fromemail($email) { $wpfrom = get_option('admin_email'); return $wpfrom;} function res_fromname($email){ $wpfrom = get_option('blogname'); return $wpfrom;} add_filter('wp_mail_from', 'res_fromemail'); add_filter('wp_mail_from_name', 'res_fromname');
4. Hide new WordPress admin bar.
// Lose New WordPress Admin Bar add_filter('show_admin_bar', '__return_false');
5. Change the default WordPress excerpt length.
// Excerpt Length function my_excerpt_length($length) {return 20;} // 20 sets the number of characters add_filter('excerpt_length', 'my_excerpt_length');
QUICK TIP: Setting up your functions.php file.
<?php // // ↑ // Place any of the above functions in here! :) // ↓ // ?>
I hope this helps you guys! Please let me know (via the comments or Twitter) if you have any questions about them or need help using them! Thanks! :)
37 notes · View notes
selfblogger · 9 years ago
Text
Allow people to automatically submit your post to Digg
Self Blogger Self Blogger - Blog Tips that help you to make money online
Adding this snippet to single.php or index.php templates of your wordpress theme will allow people to automatically submit your post to digg with a single click.  
The post Allow people to automatically submit your post to Digg appeared first on Self Blogger.
from Allow people to automatically submit your post to Digg
0 notes
computermagazine · 10 years ago
Text
10 WordPress Snippets For Theme Customizations
10 WordPress Snippets For Theme Customizations
When you are using WordPress, it is extremely easy to change the look of your website, thanks to themes. There are lots (like a whole bunch) of WordPress themes available both for free or for a premium price. Pick a theme, install it, and you can get a completely new look for your website within minutes.
But beyond giving the look and feel, a WordPress themecan be extended in many ways as well.…
View On WordPress
0 notes
zythemesposts · 5 years ago
Text
How to exclude categories from the WordPress category widget
if you need to exclude some categories from the WordPress category widget which finds it as a default WordPress widget you can do it in just one minute using this code snippet. Steps to exclude categories from the WordPress category widget: Open the WordPress admin panel then go to Appearance > Theme Editor Open theme […]
The post How to exclude categories from the WordPress category widget appeared first on Zytheme.
, https://zytheme.com/?p=7099
0 notes
zythemesposts · 5 years ago
Text
How to exclude categories from the WordPress category widget
if you need to exclude some categories from the WordPress category widget which finds it as a default WordPress widget you can do it in just one minute using this code snippet. Steps to exclude categories from the WordPress category widget: Open the WordPress admin panel then go to Appearance > Theme Editor Open theme […]
The post How to exclude categories from the WordPress category widget appeared first on Zytheme.
, https://zytheme.com/?p=7099
0 notes
zythemesposts · 5 years ago
Text
How to Include Custom Post Types in WordPress Search Results
The WordPress default search doesn’t include a custom post type in search results.so if you need to include a custom post type you can modify the query with pre_get_posts in just one minute using this code snippet. Steps to include custom post types: Open the WordPress admin panel then go to Appearance > Theme Editor […]
The post How to Include Custom Post Types in WordPress Search Results appeared first on Zytheme.
, https://zytheme.com/?p=7093
0 notes
zythemesposts · 5 years ago
Text
How to Include Custom Post Types in WordPress Search Results
The WordPress default search doesn’t include a custom post type in search results.so if you need to include a custom post type you can modify the query with pre_get_posts in just one minute using this code snippet. Steps to include custom post types: Open the WordPress admin panel then go to Appearance > Theme Editor […]
The post How to Include Custom Post Types in WordPress Search Results appeared first on Zytheme.
, https://zytheme.com/?p=7093
0 notes
zythemesposts · 5 years ago
Text
How To Enable All Site Options
WordPress has a page called “options.php” where have a complete list of all the settings you have within your database related to your WordPress site so if you need to add an additional option to your settings menu with a link to “all options” which will show all settings in just one minute using this […]
The post How To Enable All Site Options appeared first on Zytheme.
, https://zytheme.com/?p=7088
0 notes
zythemesposts · 5 years ago
Text
How To Disable Dashboard Widgets
WordPress dashboard has widgets for admin like the quick press, recent comments, and WordPress news so if you need to remove it from WordPress in just one minute using this code snippet. Steps to disable dashboard widgets: Open WordPress admin panel then go to Appearance > Theme Editor Open theme functions.php file, if you work […]
The post How To Disable Dashboard Widgets appeared first on Zytheme.
, https://zytheme.com/?p=7086
0 notes
selfblogger · 9 years ago
Text
How to Automatically empty trash in WordPress
Self Blogger Self Blogger - Blog Tips that help you to make money online
After releasing wordpress 2.9 version, there was a new feature “Trash” added which works just like an recycle bin. Instead of deleting permanently, you would send it in trash bin. By default this trash bin automatically empty after 30 days, but you need to do it regularly for better performance of wordpress. So in this post i will tell you methods of automatically empty trash in wordpress. There are so many free plugins available to empty your trash bin. Some of them are Quick Empty Trash and Auto Trash Delete. But don’t use plugin for this type of simple works, it
The post How to Automatically empty trash in WordPress appeared first on Self Blogger.
from How to Automatically empty trash in WordPress
0 notes