Title: Insert media automatically adding shortcode for pdf
Last modified: August 21, 2016

---

# Insert media automatically adding shortcode for pdf

 *  [bufferoverflow](https://wordpress.org/support/users/bufferoverflow/)
 * (@bufferoverflow)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/insert-media-automatically-adding-shortcode-for-pdf/)
 * Thank you for the plugin, I find it really useful.
 * In order to increase the usability of the plugin, the shortcode to display the
   pdf could automatically be inserted in place of the _a_ tag when the user insert
   a pdf in the article through the ‘Insert Media’ button.
 * The following code added to the pdfjs-viewer.php does that:
 *     ```
       function pdfjs_media_insert( $html, $id, $attachment ) {
         if ( preg_match( "/\.pdf$/i", $attachment['url'] ) ) {
           return '[pdfjs-viewer url="' . $attachment['url'] . '"]';
         } else {
           return $html;
         }
       }
   
       add_filter( 'media_send_to_editor', 'pdfjs_media_insert', 10, 3 );
       ```
   
 * Feel free to add it to the next version of the plugin.
 * [https://wordpress.org/plugins/pdfjs-viewer-shortcode/](https://wordpress.org/plugins/pdfjs-viewer-shortcode/)

Viewing 1 replies (of 1 total)

 *  [ramonjosegn](https://wordpress.org/support/users/ramonjosegn/)
 * (@ramonjosegn)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/insert-media-automatically-adding-shortcode-for-pdf/#post-4997647)
 * You can use Post Snippets plugin too for insert the code, and the best, Post 
   Snippets can use variables (if you want)

Viewing 1 replies (of 1 total)

The topic ‘Insert media automatically adding shortcode for pdf’ is closed to new
replies.

 * ![](https://ps.w.org/pdfjs-viewer-shortcode/assets/icon-256x256.png?rev=2301161)
 * [PDF.js Viewer](https://wordpress.org/plugins/pdfjs-viewer-shortcode/)
 * [Support Threads](https://wordpress.org/support/plugin/pdfjs-viewer-shortcode/)
 * [Active Topics](https://wordpress.org/support/plugin/pdfjs-viewer-shortcode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/pdfjs-viewer-shortcode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/pdfjs-viewer-shortcode/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [ramonjosegn](https://wordpress.org/support/users/ramonjosegn/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/insert-media-automatically-adding-shortcode-for-pdf/#post-4997647)
 * Status: not resolved