Show meta box only when post is being published first time

I haven’t tested this but the idea is to check the post status, if the post is not published, show the metabox otherwise don’t. function non_publish_metaboxes() { global $post; if(!isset($post)) return; if($post->post_status !== ‘publish’){ // … Show Metabox } } add_action( ‘add_meta_boxes’, ‘non_publish_metaboxes’ );

How to create a custom shortcode based on the layout?

You need to capture the attributes that passed to a shortcode. You can do that like this add_shortcode(‘testimonial’, ‘testimonial_shortcode_func’); function testimonial_shortcode_func( $atts ) { $atts = shortcode_atts( array( ‘style’ => ‘default_value_if_no_value_is_provided’, ), $atts ); if( $atts[‘style’] == ‘fancy’ ) { //do something } else if ( $atts[‘style’] == ‘something_else’ ) { //do something } //And … Read more

How to execute code only on posts older than 2 weeks

It looks like a couple of things are out of order. First, I’d definitely make sure to declare the $post global It’s also probably worth wrapping your logic in an is_single() and/or is_singular() checks Last, the section where you’re calculating the time as greater than 2 weeks, the current time and post date are switched. … Read more

How to get DEFER or ASYNC attribute to appear when I add a stylesheet with wp_enqueue_style from a plugin? [duplicate]

As per WP Code Snippet blog, it looks like this is one way: Add this code snippet to your functions.php file. // add async and defer to javascripts function wcs_defer_javascripts ($url) { if (strpos($url, ‘.js’) === FALSE) { return $url; } if (strpos($url, ‘jquery.js’)) { return $url; } return “$url’ async onload=’myinit()”; } add_filter(‘clean_url’, ‘wcs_defer_javascripts’, … Read more