• 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://www.ads-software.com/plugins/pdfjs-viewer-shortcode/

Viewing 1 replies (of 1 total)
  • 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.