Archive | Snippets

RSS feed for this section

How to Hook Into WooCommerce to Trigger Something After an Order is Placed

14 April

It could be anything, but if you’re offering a service of some kind, rather than a simple downloadable product, you may need to trigger something to happen when an order is complete. Here’s a simple snippet illustrating how you can add an action to woocommerce_payment_complete. Add something like the following to your functions.php. You’ll need […]

Comments Off on How to Hook Into WooCommerce to Trigger Something After an Order is Placed Continue Reading →

Add Author Field to bbPress Topics

13 April

Simple snippet to add an Author field to bbPress Topics: // Add Author field to Topics add_action( ‘init’, ‘custom_add_author_to_topics’ ); function custom_add_author_to_topics() { add_post_type_support( ‘topic’, ‘author’ ); } Twitter Facebook Google+ LinkedIn

How To Avoid Browser Security Errors And Embed YouTube Videos Properly On Your SSL WordPress Site

12 April

This is hopefully going to be fixed in core soon, but if you’re running into this problem, the solution is to add the following functions to functions.php: // Enbed YouTube Videos over SSL wp_oembed_add_provider(‘#https://(www\.)?youtube.com/watch.*#i’, ‘http://youtube.com/oembed?scheme=https’, true); wp_oembed_add_provider(‘https://youtu.be/*’, ‘http://youtube.com/oembed?scheme=https’, false ); Twitter Facebook Google+ LinkedIn

Comments Off on How To Avoid Browser Security Errors And Embed YouTube Videos Properly On Your SSL WordPress Site Continue Reading →

Customize WooCommerce Checkout Fields

11 April

You can use a filter to override the WooCommerce checkout fields that display, and also change their content. Here’s an example snippet of how to do that. Add it to your functions.php: // Customize Checkout Fields function custom_override_checkout_fields( $fields ) { $fields[‘billing’][‘billing_company’][‘label’] = ‘Organization’; $fields[‘billing’][‘billing_company’][‘required’] = true; $fields[‘billing’][‘billing_company’][‘placeholder’] = ‘Your Organization\’s Name’; $fields[‘order’][‘order_comments’][‘placeholder’] = ”; […]

Remove the Admin Bar From WordPress Public Side

08 April

Add the following snippet to your functions.php to remove the Admin bar from all logged in users except administrators: // Remove the admin bar function dont_show_admin_bar($content) { return ( current_user_can(“administrator”) ) ? $content : false; } add_filter( ‘show_admin_bar’ , ‘dont_show_admin_bar’); Twitter Facebook Google+ LinkedIn

Customize the WordPress RSS Feed For a Custom Post Type

07 April

Sometimes you want to customize the RSS Feed just for a custom post type, and leave the default alone. Here’s a snippet you can add to your functions.php that will allow you to do just that. You will need to add your custom-feed.php which you can base on one of WordPress’s default feed templates, found […]

Related Posts By Taxonomy

06 April

Here’s a useful function for displaying all of the related posts in a given taxonomy. I’ve used similar functions in the past in building a shortcode to display a list of the same custom post types that share a common taxonomy. function related_posts_by_taxonomy( $post_id, $taxonomy, $args=array() ) { $query = new WP_Query(); $terms = wp_get_object_terms( […]

Remove WordPress’s Automatic Paragraph Tag

06 April

Just add the following to your functions.php: // Remove automatic paragraphs remove_filter( ‘the_content’, ‘wpautop’ ); remove_filter( ‘the_excerpt’, ‘wpautop’ ); Twitter Facebook Google+ LinkedIn

Change the Default WordPress Display Name

05 April

When a new user registers, you can change the default population of the Display Name and make it, e.g., Firstname Lastname. Here’s a snippet you can add to your functions.php: // Set Display Name to Firstname Lastname function set_default_display_name( $user_id ) { $user = get_userdata( $user_id ); $name = sprintf( ‘%s %s’, $user->first_name, $user->last_name ); […]