Delivering a file instead of wordpress page

You’re on the right path with a rewrite rule. If you’re just delivering a file, you can hook an early action, check if a download was requested, then output the file and exit before WordPress ever gets to the stage of querying the database and deciding the request is a 404. // add the download … Read more

Add custom field to image editor

To add a custom field to attachments, place the following code in your functions.php. add_filter(‘attachment_fields_to_edit’, ‘edit_media_custom_field’, 11, 2 ); add_filter(‘attachment_fields_to_save’, ‘save_media_custom_field’, 11, 2 ); function edit_media_custom_field( $form_fields, $post ) { $form_fields[‘custom_field’] = array( ‘label’ => ‘Custom Field’, ‘input’ => ‘text’, ‘value’ => get_post_meta( $post->ID, ‘_custom_field’, true ) ); return $form_fields; } function save_media_custom_field( $post, $attachment … Read more

How to display a shortcode caption somewhere other than the_content

Try this: $caption_info = array(); add_filter( ‘img_caption_shortcode’, ‘capture_caption’, 10, 3 ); function capture_caption( $blank = ”, $attr, $content ) { global $caption_info; $caption_info[] = array(‘attr’ => $attr, ‘content’ => $content ); return ‘ ‘; } It will save info from all captions into global $caption_info variable and suppress their display in content (space is returned … 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

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