Title: shortcode or php instead of automatic insertion?
Last modified: August 22, 2016

---

# shortcode or php instead of automatic insertion?

 *  Resolved [jasonday](https://wordpress.org/support/users/jasonday/)
 * (@jasonday)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/shortcode-or-php-instead-of-automatic-insertion/)
 * Hi,
 * I want more control over where the attachments are shown. I don’t want it to 
   have it be automatic. Is there a way to turn off automatic insertion and use 
   a shortcode or php snippet instead?
 * [https://wordpress.org/plugins/wp-attachments/](https://wordpress.org/plugins/wp-attachments/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [graffig](https://wordpress.org/support/users/graffig/)
 * (@graffig)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/shortcode-or-php-instead-of-automatic-insertion/#post-5580206)
 * I would love this function too – the ability to add to my custom post types via
   shortcode would be a bonus!
 * Many thanks
 *  Plugin Author [Marco Milesi](https://wordpress.org/support/users/milmor/)
 * (@milmor)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/shortcode-or-php-instead-of-automatic-insertion/#post-5580249)
 * Hi,
    unfortunately at the moment there isn’t that possbility. I will add it soon.
 *  [Glenton](https://wordpress.org/support/users/chosen1234/)
 * (@chosen1234)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/shortcode-or-php-instead-of-automatic-insertion/#post-5580257)
 * Yes this function is very much needed, it’s the one thing that’s keeping me from
   using the plugin. 🙁
 *  [raintek](https://wordpress.org/support/users/raintek/)
 * (@raintek)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/shortcode-or-php-instead-of-automatic-insertion/#post-5580272)
 * Is there anyway to delete or turn off automatic insertion to post?
 *  Plugin Author [Marco Milesi](https://wordpress.org/support/users/milmor/)
 * (@milmor)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/shortcode-or-php-instead-of-automatic-insertion/#post-5580280)
 * These feature will be added soon soon 🙂
 *  [Mithun Sridharan](https://wordpress.org/support/users/mithungmxnet/)
 * (@mithungmxnet)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/shortcode-or-php-instead-of-automatic-insertion/#post-5580297)
 * Dear all,
 * Actually, this function could be used as is. To avoid automatic appending to 
   post content, comment out the line:
 * `add_filter('the_content', 'wpatt_content_filter');`
 * Once you’ve done this, all that’s left to do is to make a call to the function:
   _wpatt\_content\_filter_
 * I’ve commented out the line as before and added a separate function based on 
   the code to my functions.php. It looks like this:
 *     ```
       function show_attachments($content) {
           global $post;
           $somethingtoshow = 0;
           $content_l = null;
   
           $checkrestrict = false;
           if ( get_option('wpatt_option_restrictload') && !is_single() && !is_page() ) { $checkrestrict = true; }
   
           if ($post->ID == '0' || $post->ID == NULL || get_post_meta($post->ID, 'wpa_off', true) || post_password_required() || $checkrestrict ) { return $content; }
   
           $attachments = get_posts(array(
               'post_type' => 'attachment',
               'orderby' => 'menu_order',
               'order' => 'ASC',
               'posts_per_page' => 100,
               'post_parent' => $post->ID
           ));
   
           if ($attachments) {
               $content_l .= '<!-- WP Attachments --><ul class="post-attachments">';
               foreach ($attachments as $attachment) {
   
                   $wpatt_option_includeimages_get = get_option('wpatt_option_includeimages');
                   if ($wpatt_option_includeimages_get == '1') {
                   } else if ( wp_attachment_is_image( $attachment->ID ) ) {
                       continue;
                   }
                   $somethingtoshow = 1;
   
                   $class = "post-attachment mime-" . sanitize_title($attachment->post_mime_type);
   
                   if ($wpatt_option_targetblank_get == '1') { $content_l .= 'target="_blank" '; }
   
                   if ((file_exists(get_attached_file($attachment->ID)))) {
                       $wpatt_fs = wpatt_format_bytes(filesize(get_attached_file($attachment->ID)));
                   } else {
                       $wpatt_fs = 'ERROR';
                   }
                   $wpatt_date = new DateTime($attachment->post_date);
   
                   switch ( get_option('wpa_template') ) {
                       case 1: //STANDARD WITH DATE
                           $wpattachments_string = '<a href="%URL%">%TITLE%</a> <small>(%SIZE%)</small> <div style="float:right;">%DATE%</div>';
                           break;
                       case 2: //EXTENDED
                           $wpattachments_string = '<a href="%URL%">%TITLE%</a> <small>• %SIZE% • %DOWNLOADS% click</small> <div style="float:right;">%DATE%</div><br><small>%CAPTION%</small>';
                           break;
                       case 3: //CUSTOM
                           $wpattachments_string =  html_entity_decode( get_option('wpa_template_custom') );
                           break;
                       default: //DEFAULT
                           $wpattachments_string = '<a href="%URL%">%TITLE%</a> <small>(%SIZE%)</small>';
                   }
   
                   if ( get_option('wpatt_option_targetblank') ) {
                       $wpattachments_string = str_replace('<a href', '<a target="_blank" href', $wpattachments_string);
                   }
   
                   if ( get_option('wpatt_counter') ) {
                       $url = add_query_arg( 'download', $attachment->ID, get_permalink() );
                   } else {
                       $url = wp_get_attachment_url($attachment->ID);
                   }
                   $wpattachments_string = str_replace("%URL%", $url, $wpattachments_string);
                   $wpattachments_string = str_replace("%TITLE%", $attachment->post_title, $wpattachments_string);
                   $wpattachments_string = str_replace("%SIZE%", $wpatt_fs, $wpattachments_string);
                   $wpattachments_string = str_replace("%DATE%", $wpatt_date->format(get_option('wpatt_option_date_localization')), $wpattachments_string);
                   $wpattachments_string = str_replace("%CAPTION%", $attachment->post_excerpt, $wpattachments_string);
                   $wpattachments_string = str_replace("%DESCRIPTION%", $attachment->post_content, $wpattachments_string);
                   $wpattachments_string = str_replace("%AUTHOR%", get_the_author_meta( 'display_name', $attachment->post_author), $wpattachments_string);
   
                   $wpattachments_string = str_replace("%DOWNLOADS%", wpa_get_downloads($attachment->ID), $wpattachments_string);
   
                   $content_l .= '<li class="' . $class . '">' . $wpattachments_string . '</li>';
   
                   }
               $content_l .= '</ul>';
               }
       	if ($somethingtoshow == 1) {
       		$content .= $content_l;
       	} else {
       		$content .= 'No downloads available!';
       	}
           return $content;
       }
       ```
   
 * Basically, it’s the same function as _wpatt\_content\_filter_, but I’ve added
   a couple of lines if no attachments are available:
 *     ```
       if ($somethingtoshow == 1) {
       		$content .= $content_l;
       	} else {
       		$content .= 'No downloads available!';
       	}
       ```
   
 * The only risk is that these changes may be overwritten in case of a plugin update,
   but for the moment, these changes work well for me. Please note that I’m not 
   checking whether the plugin is activated or any other checks; I’m doing these
   steps elsewhere in my theme, so you may want to check whether the function, _wpatt\
   _content\_filter_ exists before using it, else you’ll see a white screen.
 * – Mithun

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘shortcode or php instead of automatic insertion?’ is closed to new replies.

 * ![](https://ps.w.org/wp-attachments/assets/icon-256x256.png?rev=2617427)
 * [WP Attachments](https://wordpress.org/plugins/wp-attachments/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-attachments/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-attachments/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-attachments/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-attachments/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-attachments/reviews/)

## Tags

 * [attachment](https://wordpress.org/support/topic-tag/attachment/)

 * 6 replies
 * 6 participants
 * Last reply from: [Mithun Sridharan](https://wordpress.org/support/users/mithungmxnet/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/shortcode-or-php-instead-of-automatic-insertion/#post-5580297)
 * Status: resolved