How do I change attachment slug from name to id

Use the add_attachment hook to update the slug after the attachment has been inserted: function wpse_182454_attachment_id_as_slug( $post_id ) { if ( get_post_field( ‘post_name’, $post_id ) != $post_id ) { wp_update_post( array( ‘ID’ => $post_id, ‘post_name’ => ( string ) $post_id, ) ); } } add_action( ‘add_attachment’, ‘wpse_182454_attachment_id_as_slug’ );

shortcode get thumbnail size

I think your code is very close, try to use wp_get_attachment_image_src() instead: function thumb_medium( $atts, $content = null ) { // return wp_get_attachment_url( get_post_thumbnail_id( $post_id, ‘medium’) ); global $post; $thumb_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘medium’ )[0]; if ($thumb_url) { return $thumb_url; } } add_shortcode(“get_urlthumb”, “thumb_medium”);

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

How to access featured image?

get_the_post_thumbnail ( $post/$post_id, $sizes, $attr ) will give you the featured image as html to output. get_post_thumbnail_id ( get_the_ID ( ) ) will give you the ID of the featured image so you can use it to get more information. Getting the thumbnail ID is essentially accessing the the post’s meta data: $image_id = get_post_meta( … Read more

add the post as canonical for attachment page wordpress

Here’s an (untested) example where we inject into the header tag on attachment’s pages, the canonical link of the attached post: add_action( ‘wp_head’, ‘wpse_attachment_parent_canonical’ ); function wpse_attachment_parent_canonical() { // Only target attachment’s pages if( ! is_attachment() ) return; $object = get_queried_object(); // Make sure we’re dealing with a WP_Post object if ( ! is_a( $object, … Read more

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