How To Use YouTube Url Stored In Custom Field To Get Video Image and Set it As Featured Image

function set_youtube_as_featured_image($post_id) { if( has_post_thumbnail($post_id) ) return; $url = get_post_meta($post_id, ‘ci_cpt_video_link’, true); if ( $url && filter_var($url, FILTER_VALIDATE_URL) ) { // getting thumb url from video url parse_str( parse_url( $url, PHP_URL_QUERY ), $youtube_vars ); $youtube_id = $youtube_vars[‘v’]; $youtube_thumb_url=”http://img.youtube.com/vi/” . $youtube_id . ‘/0.jpg’; // download and save thumb $get = wp_remote_get( $youtube_thumb_url ); $mime_type = wp_remote_retrieve_header( … Read more

How to get featured image thumbnail to open larger version in attachment page?

Use get_attachment_link to get a link to the attachment page or take a look at wp_get_attachment_link which might simplify the process. <?php if(has_post_thumbnail()) : ?> <div class=”spudpictureandcontentwrapper”> <div class=”illustration”><?php $attachment_id = get_post_thumbnail_id(); $large_image_url = wp_get_attachment_image_src($attachment_id, ‘large’); $attachment_page = get_attachment_link($attachment_id); echo ‘<a href=”‘ . esc_url($attachment_page) . ‘” title=”‘ . esc_attr(get_the_title($attachment_id)) . ‘” >’; the_post_thumbnail(‘thumbnail’); ?> </a></div> … Read more

Default thumb – how to set it

While there’s no such functionality built into core, there’s a Track Ticket I proposed 2 years ago. You can simply rip of the functionality from the suggested wp_default_img() function. I’ll greatly appreciate any support in comments on that ticket, as this would be highly needed for every theme developer. Thanks in advance. MU-Plugin The following … Read more

Use the_post_thumbnail as background image in LESS CSS [closed]

There’s nothing wrong with an inline style in this case – just set all your other rules in your LESS (like background position, repeat, size), and then in your template: <div class=”something”<?php if ( $id = get_post_thumbnail_id() ) { if ( $src = wp_get_attachment_url( $id ) ) printf( ‘ style=”background-image: url(%s);”‘, $src ); } ?>>

Getting featured image of particular size.

Please refer to the WP-Admin » Settings » Media. There you will find all the image sizes a theme creates. Basically the WordPress by default creates three sizes unless the Original: Large size (Default: 1024 x 1024) Medium size (Default: 300 x 300) Thumbnail size (Default: 150 x 150) From the admin panel you can … Read more

Better way to show Description and image Captions

There is nothing WordPress specific here, but you could make your code easier to read by removing the repeating parts. if ( $id = get_post_thumbnail_id() ) { $post = get_post( $id ); $data = array( $post->post_content, $post->post_excerpt ); // remove empty elements from array $data = array_map( ‘trim’, $data ); $data = array_filter( $data ); … Read more

Is it possible to add the_post_thumbnail to style.css?

If you want to add background image you can do inline css in html PHP: <?php if(has_post_thumbnail()) { $desktop_src = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘desktop’); $ipad_src = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘ipad’); $mobile_src = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘mobile’); $desktop = ‘style=”background: url(‘.$desktop_src[0].’);”‘; $ipad = ‘style=”background: url(‘.$ipad_src[0].’);”‘; $mobile=”style=”background: url(“.$mobile_src[0].’);”‘; } ?> HTML: <div id=”desktop” <?php echo $desktop; ?>></div> <div id=”ipad” <?php echo $ipad; ?>></div> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)