expire wordpress user posts

You can set the expire date as post meta value. In single.php you can easily show that date by querying the post meta. See update_post_meta() and get_post_meta() Now, the second part of your question is pretty tricky. I can think of 2 solutions. Cron You can use wordpress cron to run at a time interval … Read more

Automatically set the featured image

Method 1: Using the publish_post hook* and media_sideload_image() Here we will upload an image from a URL, attach it to the post, and set it as the featured image when the post is published. *Actually, we’re using the dynamic hook {$new_status}_{$post->post_type}, which refers transitioning a post post type to the publish status. See wp-includes/post.php for … Read more

Removing custom background and header feature in child theme

Both the header and background image features setup some globals in order to work, unsetting those globals seems to have some effect, and at the least removes them from the administration side. add_action(‘after_setup_theme’, ‘remove_theme_features’, 11 ); function remove_theme_features() { $GLOBALS[‘custom_background’] = ‘kill_theme_features’; $GLOBALS[‘custom_image_header’] = ‘kill_theme_features’; } class kill_theme_features { function init() { return false; } … Read more

Hide old attachments from wp media library

You can adjust the attachment query in the media library popup, through the ajax_query_attachments_args filter. Here are two PHP 5.4+ examples: Example #1: Show only attachments that where uploaded during the last 24 hours: /** * Media Library popup * – Only display attachments uploaded during the last 24 hours: */ add_filter( ‘ajax_query_attachments_args’, function( $args … Read more

Variable scope in WordPress functions.php

What is the scope of variables you declare at the top of functions.php, outside of any of the individual functions? This is a general PHP question… Variables inside a function are only available inside that function. Variables outside of functions are available anywhere outside of functions, but not inside any function. This means there’s one … Read more

Enqueue Script with data attributes

Please try code given below: function add_data_attribute($tag, $handle) { if ( ‘chargebee’ !== $handle ) return $tag; return str_replace( ‘ src’, ‘ data-cb-site=”mydomainame” src’, $tag ); } add_filter(‘script_loader_tag’, ‘add_data_attribute’, 10, 2);

How do I make my function add variables/values to the $post object?

Like any other php object, you can add items to the $post object like so: $post->my_new_val_name=”my new value”; I don’t know exactly what you’re trying to do, but inside a function hooked to the_post, you can assign new values and return the object. function my_func($post) { $post->my_new_val_name=”my new value”; return $post; } add_action( ‘the_post’, ‘my_func’ … Read more