PDF Embedder Documentation

Documentation, Reference Materials, and Tutorials for PDF Embedder

Get access to
Powerful Features!

Home » Documentation » Advanced Solutions » Preventing Automatic Shortcode Insertion

Preventing Automatic Shortcode Insertion

When you insert a PDF from the Media Library into a post, PDF Embedder automatically places a [pdf-embedder] shortcode in the editor. That default behaviour works well for most use cases, but there are situations where you want a plain link instead.

This guide explains when and why to disable automatic shortcode insertion, and how to add the PHP filter that switches the default back to WordPress’s standard link behaviour.


Why disable automatic shortcode insertion?

Two common scenarios call for this change:

  • You want the Media Library to insert a direct file link by default, and only use the shortcode when you add it manually.
  • Another plugin uses the Media Library to select files (such as a form plugin or gallery builder) and the [pdf-embedder] shortcode breaks its insertion logic.

In both cases, disabling automatic insertion stops PDF Embedder from intercepting the Media Library’s default output.

Adding the override filter

Add the following PHP snippet to your site. It hooks into pdfemb_override_send_to_editor and returns the standard WordPress HTML link instead of the shortcode.

add_filter('pdfemb_override_send_to_editor', 'my_pdfemb_override_send_to_editor', 10, 4);

function my_pdfemb_override_send_to_editor($shortcode, $html, $id, $attachment) {
    return $html;
}
Code language: PHP (php)

Add this code using one of the following methods:

Using WPCode (recommended): Install the free WPCode plugin, go to Code Snippets > Add Snippet, paste the code, and activate it.

Adding to the functions.php: Add the code to your active theme’s functions.php file.

Once active, selecting a PDF from the Media Library inserts a standard <a href> link to the file. To embed a PDF using the viewer, add the shortcode manually or use the PDF Embedder block.

What this does not affect

This filter only changes the behaviour of the Insert into post action in the classic Media Library modal. It does not affect:

  • PDFs already embedded via shortcode elsewhere on your site
  • The PDF Embedder block in the Gutenberg editor
  • Shortcodes you type or paste manually

Still have questions? We’re here to help!

Last Modified: