Get the attachment URL on single.php

The the_attachment_link returns an HTML link, so use this code: if ( $attachments = get_children( array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘numberposts’ => 1, ‘post_status’ => null, ‘post_parent’ => $post->ID ) ) ); foreach ( $attachments as $attachment ) { echo wp_get_attachment_link( $attachment->ID, ” , true, false, ‘Link to image attachment’ ); } Here … Read more

ID of images from gallery

You can find out the IDs of which images are included in a gallery by switching to the Text editor tab and look for a piece of code like this: The comma-separated list of image IDs are enclosed in the ids attribute If you’re looking to find out IDs of existing images in order to … Read more

How to upload image from front end and save in media library?

Now I have an answer for my own question.I solved this issue by using this code.I add this code just for sharing and helping other as it works for me. <input type=”file” name=”my_file_upload” id=”my_file_upload_id” class=”bg_checkbox” > function register_team_show_case_setting() { //register our settings register_setting(‘my_team_show_case_setting’, ‘my_file_upload’); } add_action(‘admin_init’, ‘register_team_show_case_setting’); Code to upload and save image: require_once( ABSPATH … Read more

Change the Permalink for wordpress attachment

Your rule works with the attachment ID, so I’m not sure how you’re using the title, but the answer is almost identical in either case. The filter you want is attachment_link: function wpd_attachment_link( $link, $post_id ){ $post = get_post( $post_id ); return home_url( ‘/images/’ . $post->post_title ); } add_filter( ‘attachment_link’, ‘wpd_attachment_link’, 20, 2 ); Change … Read more

Add_Filter example for wp_get_attachment_link

Look at the function in wp-includes/post-template.php. There you see what information you can get: apply_filters( ‘wp_get_attachment_link’ , “<a href=”https://wordpress.stackexchange.com/questions/16809/$url” title=”$post_title”>$link_text</a>” , $id , $size , $permalink , $icon , $text ); Note that you cannot access the $link_text and the $_post object as a standalone variables. Bug? Bug! In your filter you cannot change the … Read more

Making images from single.php pointing to an attachment .php template

If I understand you correctly, you need to link your images not to the file, but to the attachment template (attachment.php). If so, then try the following code in your single.php: <?php if( has_post_thumbnail() ) { $attachment_page_url=””; $attachment_page_url = get_attachment_link( get_post_thumbnail_id() ); ?> <a href=”<?php echo $attachment_page_url; ?>” class=”featured-image”> <?php the_post_thumbnail(); ?> </a> <?php } … Read more

Gel all image from certain post type

Try this code in your template. $query = new WP_Query( array( ‘post_type’ => ‘custom-post’, ‘posts_per_page’ => -1 ) ); if( $query->have_posts() ){ while($query->have_posts()){ $query->the_post(); $image_query = new WP_Query( array( ‘post_type’ => ‘attachment’, ‘post_status’ => ‘inherit’, ‘post_mime_type’ => ‘image’, ‘posts_per_page’ => -1, ‘post_parent’ => get_the_ID() ) ); while( $image_query->have_posts() ) { $image_query->the_post(); echo wp_get_attachment_image( get_the_ID() ); … Read more

exposing attachment uploading to the front end — delicate

here is the function i use whenever i accept uploads from front end and you can use it in your template files: function insert_attachment($file_handler,$post_id,$setthumb=’false’) { // check to make sure its a successful upload if ($_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK) __return_false(); require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’); $attach_id … Read more

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