Adding a number to a date

You need get_the_time, not the_time to get the date (the latter echo‘s the value). You also need to re-evaluate how you’re trying to calculate the end date – you can’t just “add” the number of days. What if the event length was 3 but the start date was the 31st? if ( $event_length ) { … Read more

I want different post-thumbnail size depending on media size

You can use the function [wp_calculate_image_srcset()][1], a helper function to return the srcset attribute value for an image ID, the different sizes need to exist, otherwise the function return false. Here is what a link with srcset look like, <img class=”alignnone size-full wp-image-122491 ” src=”http://example.com/wp-content/uploads/2016/03/C0101-012.jpg” alt=”C0101-012″ width=”2000″ height=”1200″ srcset=”http://example.com/wp-content/uploads/2016/03/C0101-012.jpg 2000w, http://example.com/wp-content/uploads/2016/03/C0101-012-656×394.jpg 656w, http://example.com/wp-content/uploads/2016/03/C0101-012-1024×614.jpg 1024w, http://example.com/wp-content/uploads/2016/03/C0101-012-1080×648.jpg … Read more

Using get_the_excerpt in edit-post

I think (and assuming) you use (without code, it’s hard to know, how you proceed) add_meta_boxes() to do your job. Then your code is logically standing in custom functions. Your function to render the metabox, don’t get the $post global, if you didn’t define it, the function need to know from which post it must … Read more

Need help with PHP functions

add_shortcode(‘show_name’, ‘generate_content’); When WordPress finds a [show_name] shortcode tag in content, it runs the function that matches the second parameter, which in this case is generate_content. Try renaming your show_name() function to be the same, like this: add_shortcode(‘show_name’, ‘my_show_name_func’); function my_show_name_func() { $current_user = wp_get_current_user(); $first_name = $current_user->user_firstname; return $first_name; } Everything else looks like … Read more

WooCommerce remove_action and add_action [closed]

You can create your own dedicated function and overwrite a default one when a function is in a function_exists statement. if ( ! function_exists( ‘woocommerce_template_single_add_to_cart’ ) ) {} You can use the woocommerce_template_single_add_to_cart function from wc-template-functions.php Just copy/paste this function to your woocommerce-functions.php and modify it with the statement you want. This method is simple … Read more