How to detect single.php (but not single-portfolio.php)?

You can use the following instead, if (is_singular(‘post’)) { //your code here… } Where by is_singular is the WordPress API conditional function for testing for the existence of a post type. You can also pass an array of post types if you wish. http://codex.wordpress.org/Function_Reference/is_singular

Adding a second email address to a completed order in WooCommerce [closed]

There’s actually a filter that you can use, see abstract-wc-email.php, line 214: return apply_filters( ‘woocommerce_email_recipient_’ . $this->id, $this->recipient, $this->object ); you can put the following in your functions.php: add_filter( ‘woocommerce_email_recipient_customer_completed_order’, ‘your_email_recipient_filter_function’, 10, 2); function your_email_recipient_filter_function($recipient, $object) { $recipient = $recipient . ‘, [email protected]’; return $recipient; } the only drawback is that the recipient will see … Read more

How to create a custom order status in woocommerce!

This is what I have used to create a custom order status called “Invoiced”. Add this to your theme’s functions.php // New order status AFTER woo 2.2 add_action( ‘init’, ‘register_my_new_order_statuses’ ); function register_my_new_order_statuses() { register_post_status( ‘wc-invoiced’, array( ‘label’ => _x( ‘Invoiced’, ‘Order status’, ‘woocommerce’ ), ‘public’ => true, ‘exclude_from_search’ => false, ‘show_in_admin_all_list’ => true, ‘show_in_admin_status_list’ … Read more

Add image size if page template

This has always been a bugbear for me – the lack of on-demand image sizing, and the subsequent number of files you can end up with if you have lots of sizes! I can see the logic behind your efforts – the trouble is, add_image_size only truly comes into play at point-of-upload. As such, is_page_template(..) … Read more

Add tags to the section via functions.php

The hook you’re looking for is specifically wp_head which could look something like this: function theme_xyz_header_metadata() { // Post object if needed // global $post; // Page conditional if needed // if( is_page() ){} ?> <meta name=”abc” content=”xyz” /> <?php } add_action( ‘wp_head’, ‘theme_xyz_header_metadata’ ); I believe in the long run though, since WordPress is … Read more

How to check if a user exists by a given id

Use this function: function user_id_exists($user){ global $wpdb; $count = $wpdb->get_var($wpdb->prepare(“SELECT COUNT(*) FROM $wpdb->users WHERE ID = %d”, $user)); if($count == 1){ return true; }else{ return false; } } Usage: if(user_id_exists(1)){ //it does exists } else { //it doesn’t }

How do I get the current edit page ID in the admin?

You can also use $post_id = $_GET[‘post’]; Or you can use a hook (probably better). function id_WPSE_114111() { global $post; $id = $post->ID; // do something } add_action( ‘admin_notices’, ‘id_WPSE_114111’ ); You will need to add a conditional since this will run on all admin pages, I recommend using get_current_screen(); For example to run only … Read more

File not found.