Displaying a button on each post

Use the_content hook and hook only when you are on a single page: add_filter( ‘the_content’, ‘my_button_function’ ); function my_button_function( $content ) { // See if it’s a single post or a loop if ( is_single() && in_the_loop() && is_main_query() ) { return $content . “<button onclick=\”buttonAction()\” p style=\”font-size:10px\” id=\”ActionButton\”>ACTION</button>”; } return $content; } This will … Read more

Encrypt / Decrypt Post Title and Details

To change post content before it gets saved you can use wp_insert_post_data filter. I’m using in this example just a simple/dummy way to represent the encryption, I’m just replacing each char with the correspondent ascii code. It should be replaced by your encryption method. add_filter( ‘wp_insert_post_data’ , ‘encrypt_post’ , 99, 1 ); function encrypt_post( $data … Read more

Post query – show posts from specified day and month and whole years

You can use WP_Date_Query in conjunction with WP_Query to accomplish this. $query = new \WP_Query( array( ‘posts_per_page’ => 5, ‘date_query’ => array( array( ‘day’ => date( ‘j’, current_time( ‘timestamp’ ) ), ‘month’ => date( ‘n’, current_time( ‘timestamp’ ) ), ‘before’ => ‘this year’ ) ) ) ); if ( $query->have_posts() ) : while ( $query->have_posts() … Read more

Is there any way to allow users to access content before it’s published?

You can use this in a template file: $tomr = getdate(time()+86400); //utc=gmt time in seconds, add 24 hours = 86400 seconds $args = array( ‘post_status’ => ‘future’, ‘date_query’ => array( array( ‘year’ => $tomr[‘year’], ‘month’ => $tomr[‘mon’], ‘day’ => $tomr[‘mday’], ‘column’ => ‘post_date_gmt’ //since we are using the gmt timestamp ), ), ); $query = … Read more