Need to override a global setting for PDFs on your site without editing the embeds individually? PDF Embedder provides PHP filter hooks that let you override shortcode and block attributes programmatically.
This guide covers the two available filters: one for standard shortcode and block embeds, and one specifically for attachment page embeds.
How Attribute Overrides Work
PDF Embedder resolves display settings in this order: global plugin settings first, then any attributes set directly on the shortcode or block. The PHP filters described here run after that resolution, giving you a final opportunity to override any attribute before the viewer renders.
You can also inspect the $atts['url'] value inside the filter function to apply rules selectively, for example, to apply different settings to PDFs with a specific filename pattern.
Overriding Attributes for Standard Shortcodes and Blocks
Use the pdfemb_filter_shortcode_attrs filter to modify attributes on any standard [pdf-embedder] shortcode or PDF Embedder block. This works in both the free and Premium versions.
add_filter( 'pdfemb_filter_shortcode_attrs', 'pdfemb_docs_change_sc_atts', 10, 1 );
function pdfemb_docs_change_sc_atts( $atts ) {
$atts['pagetextbox'] = 'on';
return $atts;
}
Code language: PHP (php)
This example forces the pagetextbox attribute to on for every embed. Use this approach for parameters that have no global setting in Settings > PDF Embedder.
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 functions.php: Add the code to your active theme’s functions.php file.
Overriding Attributes for Attachment Pages
Attachment pages load differently from standard embeds and use a separate filter: pdfemb_premium_viewer_render_atts. The function body is identical; only the filter name changes.
add_filter( 'pdfemb_premium_viewer_render_atts', 'pdfemb_docs_change_attpages_atts', 10, 1 );
function pdfemb_docs_change_attpages_atts( $atts ) {
$atts['pagetextbox'] = 'on';
return $atts;
}
Code language: PHP (php)
If you need the same override to apply to both standard embeds and attachment pages, add both filters using separate function names.
Applying Conditional Overrides Based on URL
Both filters receive the full $atts array, which includes $atts['url']. Use this to apply overrides only to specific PDFs:
add_filter( 'pdfemb_filter_shortcode_attrs', 'pdfemb_docs_change_sc_atts', 10, 1 );
function pdfemb_docs_change_sc_atts( $atts ) {
// Only apply to PDFs with 'annual-report' in the filename
if ( strpos( $atts['url'], 'annual-report' ) !== false ) {
$atts['download'] = 'off';
}
return $atts;
}
Code language: PHP (php)
This pattern lets different PDF files follow different rules without requiring multiple shortcodes or block configurations.