Display post image with fancybox

When you echo something, you need to be echoing the variable. You are using the_post_thumbnail_url, which in itself is already an echo statement. You should be using get_the_post_thumbnail_url instead. echo “<a class=”fancybox” rel=”group” href=”” . get_the_post_thumbnail_url( get_the_ID(), “full’ ) . “‘>”; EDIT: Also, missing the $post_id, fixed to include it in the function

Hide post if matches current month and year

Initialize an array before the first loop: $exclude = array(); Then add the ID of each post within the first loop to that array: while ($query->have_posts()) { $query->the_post(); $exclude[] = get_the_ID(); // etc… Then use that array to exclude those IDs via post__not_in in the second query: $args = array( ‘post_type’ => ‘page’, ‘post__not_in’ => … Read more

Trying to make php run in a post

Here’s a solution using a [shortcode] which doesn’t rely on running PHP inside of the content area. Here are the docs for get_post_meta() which show how that function should be called. add_shortcode( ‘buy_status’, ‘wpse249289_buy_status’ ); function wpse249289_buy_status( $atts ) { $output=””; if ( ! get_post_meta( get_the_ID(), ‘buy_status’, true ) ) { // Post meta value … Read more

PHP in post content [closed]

It was a stupid question, I just realized, if I just create a custom shortcode for it, the plugin will not wrap it in <p> tags then, or even better still just create it as a plugin of it’s own.

Auto crop images in WordPress

You can use add_image_size to create your custom size like this: add_image_size( ‘featured-works’, 220, 180, true ); then get it like this: wp_get_attachment_image_src($thumbnail_id,’featured-works’); take into account how the crop works here

Insert array data on plugin activation

You may please use this code that will help you to insert data into database register_activation_hook( __FILE__, ‘my_plugin_create_db’ ); function my_plugin_create_db() { global $wpdb; $table_name1 = $wpdb->prefix . “woo_currency”; $curr_name = array(‘Dollars’, ‘Ruble’, ‘Riel’); $curr_symbol = array(‘$’, ‘p.’, ‘៛’); $insert = $wpdb->insert($table_name1, array( ‘name’ => $curr_name, ‘symbol’ => $curr_symbol, ),array(‘%s’, ‘%s’)); } Hope this will … Read more

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