How to check for images before echo

wrap the html output in the conditional like this: <?php $image = wp_get_attachment_image_src(get_field(‘post_image1’), ‘thumbnail’); if( $image !=false ) { ?> <img src=”https://wordpress.stackexchange.com/questions/60013/<?php echo $image[0]; ?>” alt=”<?php get_the_title(get_field(‘post_image1’)) ?>” /> <?php } $image = wp_get_attachment_image_src(get_field(‘post_image2’), ‘thumbnail’); if( $image !=false ) { ?> <img src=”https://wordpress.stackexchange.com/questions/60013/<?php echo $image[0]; ?>” alt=”<?php get_the_title(get_field(‘post_image2’)) ?>” /> <?php } ?>

How can I change get_the_post_thumbnail to make 100% width image?

I ended up using the following to solve my problem. <?php $image_id = get_post_thumbnail_id(); ?> <?php $image_attributes = wp_get_attachment_image_src( $image_id, ‘full’); ?> <img src=”https://wordpress.stackexchange.com/questions/65569/<?php echo $image_attributes[0]; ?>” width=”100%”>

What happened to the media manger?

The answer is obvious: no, you can’t. Why? Because there is no folders in database for media attachments, all media files are stored as single row in wp_posts table. I suppose it does not really matter where your media files are stored, it could be your hosting or CDN network, somebody else hosting, etc 🙂 … Read more

Replace post/page titles with an image in WordPress

I would actually handle this with CSS. In your style.css file add something like this: .page-title h1 { text-indent: -9999px; background: url(images/your_logo.png) 10px 10px no-repeat; height: 100%; } You’ll then make sure that your logo is added to your theme’s images folder. Also, adjust the size of the image accordingly, or you can also adjust … Read more

Does WP create multiple images?

WordPress shows whichever image is requested by the function that outputs those images in the template. The presentation of images is entirely up to the theme developer, WordPress doesn’t make this decision on its own. For example, the_post_thumbnail function: the_post_thumbnail(‘thumbnail’); // Thumbnail (default 150px x 150px max) the_post_thumbnail(‘medium’); // Medium resolution (default 300px x 300px … Read more

Time Based change of image

I believe you’re using the wrong function. get_the_time() doesn’t actually return the current time but instead the time of when the post was published. Maybe what you’re looking to use is date( ‘H’ ).

Using featured img as div background

Try something like this: <?php global $post; $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, ” ); $default = get_template_directory_uri().”/assets/images/backgrounds/highway.jpg”; $bgimg = (isset($src[1])) ? $src[0] : $default; ?> <style type=”text/css”> .parallax { background-image: url(<?= $bgimg ?>); } </style> wp_get_attachment_image_src() says it returns false when not found, but for some reason I’ve had bad time with … Read more