Tag Info

New answers tagged

0

get_user_meta($userId, 'simple_local_avatar'); Simple Local Avatars uses meta fields to store the avatar, so you can simply retrieve the value(s) by calling get_user_meta and grabbing the 'simple_local_avatar' field. You'll get returned an array like so: array ( [full] => 'http://...', [96] => 'http://...', [32] => 'http://...' )


1

There's no native function, but the RICG Responsive Images plugin will add a srcset attribute with the available image sizes. Srcset (along with the <picture> element), is steadily gaining browser support - it doesn't need any javascript and it's up to the browser to decide which is the correct image to load. The attribute is added for posts where ...


0

function get_attachment_id_from_src ($image_src) { global $wpdb; $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'"; $id = $wpdb->get_var($query); return $id; }


0

Try using absolute paths in src attribute. If your images are in your theme folder, you can use: <img src="<?php bloginfo('template_url'); ?>/yourImageFolder/yourImage.jpg" /> This way, URLs will be absolute even if you move your WordPress site to another server.


0

Use wp_get_attachment_metadata(). Using your example: $img_data = wp_get_attachment_metadata( $attachment_id ); $w = $img_data['width']; $h = $img_data['height']; if ($w > $h) { $class = "col-sm-12"; } else { $class = "col-sm-6"; } Though, to get the attachment ID, you'll either have to put a filter that acts on every image or create a loop ...


1

Lets start with your first code. If you add texts, captions etc. a shortcode will be generated: [caption] The function img_caption_shortcode() in wp-content/media.php is responsible to execute the shortcode. But this shortcode is only produced, when you use captions. Otherwise, it will be simply inserted the <a>- and <img>-Tag. who decides, what ...


7

You can use the wp_generate_attachment_metadata filter: function wpse_183835_to_jpeg( $meta, $post_id ) { $sizes_to_convert = array( 'thumbnail', ); $path = dirname( get_attached_file( $post_id ) ); foreach ( $sizes_to_convert as $size ) { if ( ! empty( $meta['sizes'][ $size ] ) ) { $data = $meta['sizes'][ $size ...


0

Old question but still getting search traffic so for everyone else: You can accomplish what you describe by filtering the gallery shortcode attributes. Also useful if you want to change the default image size, columns, etc. function gallery_should_link_to_files($out, $pairs, $atts) { $atts = shortcode_atts( array( 'link' => 'file' ), $atts ...


0

Please include the following files before using media_sideload_image() for it to work, require_once(ABSPATH . 'wp-admin/includes/media.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/image.php'); Reference, WP Codex: media_sideload_image


1

I've had the same problem and found it was due to the upload file size set for the server (in my case 2mb). There is another setting which escapes me at this point, but is basically a limit on the amount of space that can be used to process uploaded images...which WordPress does when it re-sizes the images on upload. Unfortunately, unless you have root ...


0

try this to exclude images from search. Add code to your functions.php: // Exclude images from search results - WordPress add_action( 'init', 'exclude_images_from_search_results' ); function exclude_images_from_search_results() { global $wp_post_types; $wp_post_types['attachment']->exclude_from_search = true; }


2

The correct core function should be current_time() Untested, but your code ought to look something like: if (current_time('H') >= 8 && current_time('H') < 20)


2

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' ).


0

There's one nasty bug in the solution above. The solution works as a charm for new images, but for old images, you should never compare to $upload_dir['path'] because that's the current upload folder of the current month. Replace the following: //$large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file']; $large_image_location ...


0

I have no time to write at your code, but with your help works for me function wms_add_headerimage_cb( $post ){ //campuri $values = get_post_custom( $post->ID ); $headerpageimage = isset( $values['headerpageimage'][0] ) ? esc_attr( $values['headerpageimage'][0] ) : ''; $img_src = wp_get_attachment_image_src( $headerpageimage, ...


1

Assuming we are viewing some king of single - post, page, custom post type etc. <?php $imgs_meta = get_post_meta( get_the_ID(), 'AP_post_image', true ); if ( '' != $imgs_meta ) { $imgs = explode( ',', $imgs_meta ); foreach ( $imgs as $src ) printf( '<img src="%s" />', esc_url( $src ) ); }


3

WordPress doesn't store path of generated sizes anywhere, you need to build it. As suggested by @kraftner in comments, wp_get_attachment_metadata() can be used to obtain some of the pieces you need to build the path. An alternative is image_get_intermediate_size(). The missing piece is the absolute path of upload folder. In theory, that can be retrieved ...


0

Almost by definition thumbnails has to be on your server. It is possible to write code that imports the image and produces the thumbnail from it (and I am sure there are answers here with code which does similar things), but this will automatically make you a copyright infringer which is illegal in about 95% of the countries in the world. I can only guess ...


1

You have to use single_product_large_thumbnail_size filter for Single Product page. something like: function custom_product_large_thumbnail_size() { return 'gallery'; } add_filter('single_product_large_thumbnail_size', 'custom_product_large_thumbnail_size');


-1

You have to regenerate all the images with the specified sizes and for that you can use Regenerate Thumbnails plugin from wordpress. you can download it from http://wordpress.org/plugins/regenerate-thumbnails/


0

It's this right here. Make that 100% or take it away and it works as you thought it should. edit: I'm not sure I answered on the right thing afterall. But this will fix the one/two pixel gap between the left hand navigation against the picture on the right. edit2: Yeah, it was what I thought, and the other fix does the same thing as well.


1

This isn't a WordPress issue, although it IS an easy CSS fix. The small space between the end of image and the slideshow is axtually 2 pixels wide and caused by the #left-area div. You can just up the width by 2 pixels on #left-area. Like this: #left-area { width: 639px; } It is currently 637px. You could also up the padding-left by 2 pixels to ...


0

There are multiple solutions: Use CSS for post images: .post img { height: 300px; width: auto; } Use a custom thumbnail size. Either in Settings -> Media or use a third-party plugin to generate them. Another way would be to code your own: function custom_image_sizes() { add_theme_support('post-thumbnails'); add_image_size('breaking-news', 9999, ...


1

The renaming to test1.jpg is not due to any cropping / resizing functions WordPress. This is because you already had a file named test.jpg uploaded, and WordPress does not replace files if one exists in the folder that has the same name. If, for some reason you want it to replace files rather than rename it (not recommended) you can use a plugin like: ...


0

You can see this link. there has some example like add_action( 'after_setup_theme', 'baw_theme_setup' ); function baw_theme_setup() { add_image_size( 'category-thumb', 300 ); // 300 pixels wide (and unlimited height) add_image_size( 'homepage-thumb', 220, 180, true ); // (cropped) }



Top 50 recent answers are included