How do i upload an image and return the image id?

Take a look at side loading images. media_sideload_image()/wp_handle_sideload() and get the ID from the URL. attachment_url_to_postid. <?php $url = “http://wordpress.org/about/images/logos/wordpress-logo-stacked-rgb.png”; $title = “Some Image Title”; $alt_text = “Some Alt Text”; require_once(ABSPATH . ‘wp-admin/includes/media.php’); require_once(ABSPATH . ‘wp-admin/includes/file.php’); require_once(ABSPATH . ‘wp-admin/includes/image.php’); // sideload the image — requires the files above to work correctly $src = media_sideload_image( $url, … Read more

How to grab first image attached to post and display in RSS feed?

i actually just finished working on a site that needed images in his feeds so i ended up using this: function ba_post_image_feeds($content) { global $post,$posts; $first_img = ”; ob_start(); ob_end_clean(); $output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches); $first_img = $matches [1] [0]; if(!empty($first_img)){ $content=”<div>” . $first_img . ‘</div>’ . $content; } return $content; } add_filter(‘the_excerpt_rss’, ‘ba_post_image_feeds’); add_filter(‘the_content_feed’, … Read more

How can you upload an image from within a settings page?

WordPress provides a convenient function for just this purpose: wp_handle_upload(). Assuming that you already have the appropriate file form field in your settings page, and that you’re using register_setting() for your options, and therefore already have an options validation callback, simply handle the file form field data using wp_handle_upload(). Here’s an example: <?php // Validate … Read more

Use Media Library to manage galleries like Nextgen (with folders, albums, collections, tags, categories, terms…)

I’ve had this same problem for ages and have currently landed on the following combination of plugins to resolve the issue: Media Tags Tag Gallery Cleaner Gallery Additionally, I made two modifications to the tag gallery plugin (to remove TimThumb and allow reverse ordering) This solution still has a lot of downsides including that it … Read more

Preview Image Path in Admin Section

This is not a answer, is an extended comment with the link to the solution. First, while testing, one of my test sites wasn’t showing the Featured Image uploaded to the folder /wp-content/uploads/POST_ID/image_name.jpg. Same problem as the OP. But, it was not displaying any path to the image. And the bug was that the installation … Read more

Width 100%: Aspect ratio of image

A + C: img.resize-proportionally { max-width: 100%; height: auto; } As an aside, for the above to work, you shouldn’t attempt B. Having width and height attributes in the img tag is good.

WordPress Image Editor doesn’t update thumbs specified with `add_image_size()`

Like it was said, WordPress only generate thumbnails in the new sizes of the new media uploaded. The old images’ thumbs doesn’t get generated automatically. For this situation, I strongly recommend the following plugin: http://wordpress.org/plugins/force-regenerate-thumbnails/ It is pretty simple and unobtrusive. It just adds a new item on the wp-admin menu for you to regenerate … Read more

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