Way to store featured image width and height in two separate variables?

You can always use the wp_get_additional_image_sizes() function to retrieve an image “size” (i.e. width, height, and the ‘crop’ option), like this: $image_sizes = wp_get_additional_image_sizes(); if ( isset( $image_sizes[‘slide_image’] ) ) { $size = $image_sizes[‘slide_image’]; var_dump( $size ); // Demo echo $size[‘width’]; // Demo } UPDATE In reply to your comment, i want to get the … Read more

Check if the image size is available and if not use ‘full’ image size

I don’t see why something like this wouldnt work! $med_post_thumb = get_the_post_thumbnail($post->ID, ‘medium_post_thumbnails’, array(‘class’ => ‘img-fluid’)). ‘</a></div>’; $full_post_thumb = get_the_post_thumbnail($post->ID, ‘FULL SIZE GOES HERE’, array(‘class’ => ‘img-fluid’)). ‘</a></div>’; if ($med_post_thumb == NULL) { echo $full_post_thumb; } else { echo $med_post_thumb; }

How to retrieve the current post’s generated featured image size?

Have a look to wp_get_attachment_image_src(), which gives precisely data you need (URL and dimensions). Which help to figure out your problem. sample code $image_attributes = wp_get_attachment_image_src( $attachment_id = 10 ); if ( $image_attributes ) : ?> <img src=”https://wordpress.stackexchange.com/questions/302831/<?php echo $image_attributes[0]; ?>” width=”<?php echo $image_attributes[1]; ?>” height=”<?php echo $image_attributes[2]; ?>” /> <?php endif; ?> The return … Read more

add_action template_redirect not working for home page

Be careful not to confuse the two query conditionals. Whether is_home() or is_front_page() return true or false depends on the values of certain option values. When using these query conditionals: If ‘posts’ == get_option( ‘show_on_front’ ): On the site front page: is_front_page() will return true is_home() will return true If assigned, WordPress ignores the pages … Read more

Changing parent element’s class or style

So, the elements should be changed into <div class=”icheckbox disabled hide_empty” style=””> that’s different from the goal stated in the question where you say you want to add class “hide_empty” to the parent <li> of the <div class=”icheckbox”>. The code posted by @dhirenpatel22 should work to add class hide_empty to the li element, of course … Read more

Undefined index: action with code-snippets to change register page

You’re doing this: strtolower( $_GET[‘action’]) But you’re not checking if $_GET[‘action’] exists first. You can’t count on it being set, because when you visit wp-login.php, it doesn’t have ?action= in the URL, but this hook still fires. So you need to add isset( $_GET[‘action’] ) to your conditions: if ( strtolower($pagenow) == ‘wp-login.php’ && isset( … Read more

The Loop not looping?

I’m following your initial question. In your backend, create a page with the title Test 1, which should result in the page slug test-1. In your child theme folder, create a page template, using the filename page-test-1.php. WordPress will be loading this template, following this pattern: page-$slug.php. For more details, see here: https://developer.wordpress.org/files/2014/10/wp-hierarchy.png. In your … Read more

WordPress function, Run using Crontab

define(‘DISABLE_WP_CRON’, true); This line disables the default behaviour of WP Cron. Which is being triggered by a user that visits the site. This is bad for a couple of reasons (nobody might visit, tasks are started via apache handler instead of PHP CLI, …). Now, if you have disabled it, you need another way to … Read more

Do I need to use wp_reset_postdata for my function?

Yes you should, otherwise you could interfere with another query happening on the same page. Using $the_query->the_post(); interferes with the global $post variable, and wp_reset_postdata() serves that exact purpose, to reset the global $post variable to the original (global) query. Read more