Adding width and height to wp_get_attachment_image_src

What is ‘two’ referring to? Is that a custom image size? Place the following var_dump(‘<pre>’,$image,'</pre>’); after your declared $image variable like so, $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘two’ ); var_dump(‘<pre>’,$image,'</pre>’); and provide the results so we can inspect the output. As per Codex the second argument in this function, wp_get_attachment_image_src( $attachment_id, $size, $icon ); … Read more

Get the path of the first attached media (single.php)

I tried to write some snippet with the help of WordPress codex. Please check below and update it further as per your needs. I hope this helps: global $post; $args = array( ‘numberposts’ => 1, ‘order’ => ‘ASC’, ‘post_mime_type’ => ‘image’, ‘post_parent’ => $post->ID, ‘post_status’ => null, ‘post_type’ => ‘attachment’, ); $attachments = get_children( $args … Read more

Detach an image from a page using php

There are no core (4.8.1) functions like detach_post() or wp_update_attachment() but we can use wp_update_post() to detach attachments: $result = wp_update_post( [ ‘ID’ => $attachment_id, ‘post_parent’ => 0, // detach ] ); if( is_wp_error( $result ) ) { // error } else { // success } We can also create a helper function (untested): /** … Read more

Displaying Post Attachment(s) at Top of single.php

Attachments are considered children of the post they’re attached to, so this should work: $images=get_children( array(‘post_parent’=>$post->ID, ‘post_mime_type’=>’image’, ‘numberposts’=>1)); echo wp_get_attachment_image($images[0]->ID, ‘large’); for a large image… replace “large” with the size definition you want or a width,height array.

List Post Attachments – Remove Image Thumbnails

Instead of the_attachment_link use the following: echo wp_get_attachment_link($attachment->ID, ‘full’, false, false, true); wp_get_attachment_link is what’s being called internally by the_attachment_link, the last parameter set to true makes it output a text link instead of an image.

use wp_get_attachment_image() to show attachments

You’re obviously getting data returned for $attachments = get_posts(); otherwise, you wouldn’t be able to output $attachment->post_title. So the issue must be with your wp_get_attachment_image() call. The first thing I would check is: why are you setting the $icon parameter to true? This parameter is intended to output a mime-type icon, instead of the actual … Read more

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