Context
I have a function that overrides audio shortcode HTML rendering, thanks to a WordPress hook:
wp_audio_shortcode_override
I used it this way in an OOP plugin:
add_filter( 'wp_audio_shortcode_override' , array( $this, 'wp_audio_shortcode_override' ), 10, 2 );
In order to prevent all the HTML shortcodes from being overridden, I want to create a custom shortcode attribute:
player="default"
As far I can read from the docs and the source code, if I return an empty string ''
, the override should be off.
So I wrote this at the beginning of my render function:
public function wp_audio_shortcode_override( $html, $attr ) {
$html = ''; // This is the value to disable the shortcode override
if ( isset( $attr['player'] ) ) {
if( $attr['player'] === 'default' )
var_dump( $html );
return $html;
}
// After that, some code to fill the $html with thing to render,
// according to the shortcode attributes values
The next part of the function is how the shortcode must be overridden.
Results
- Shortcode override without conditions works
- Adding the condition in the function, and write the corresponding shortcode attribute
player="default"
in one audio shortcode, works. - Adding the same shortcode attribute value to all audio shortcodes in a post works.
- Having audio shortcodes with the attribute and some without on the same post doesn't work.
Reproduce
For this, I started from a plugin example posted here: Is it possible to control the width of the Wordpress audio player?
Assistance
What did I miss? Why can I disable the override on all shortcodes, but not selectively on the same post?