This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Ever wondered how you can tweak the playlist output in WordPress? The post_playlist filter hook is your answer. This hook lets you modify the playlist output as per your needs. Let’s dive into it!
post_playlist filter
Filters the playlist output.
apply_filters( 'post_playlist', string $output, array $attr, int $instance )Description
This is a filter hook which is used to filter the playlist output. Returning a non-empty value from the filter will short-circuit the generation of the default playlist output, returning the passed value instead.
Parameters
- $output : (string) Playlist output. Default empty.
- $attr : (array) An array of shortcode attributes.
- $instance : (int) Unique numeric ID of this playlist shortcode instance.
Live Example
Example 1: Custom Playlist Output
Passing a non-empty value to the filter will short-circuit the default output.
function weplugins_custom_playlist( $output, $attr, $instance ) { if ( 'false' == $attr['images'] || 'video' == $attr['type'] ) { // Custom logic here } return $output; } add_filter( 'post_playlist', 'weplugins_custom_playlist', 10, 3 );Example 2: Running the Hook
To run the hook, copy the example below.
$var = apply_filters( 'post_playlist', $var, $attr, $instance ); if ( !empty( $var ) ) { // everything has led up to this point... }Example 3: Adding and Removing Hook Callback
The following example is for adding a hook callback.
// define the post_playlist callback function weplugins_filter_post_playlist( $var, $attr, $instance ) { // make filter magic happen here... return $var; }; add_filter( 'post_playlist', 'weplugins_filter_post_playlist', 10, 3 );To remove a hook callback, use the example below.
remove_filter( 'post_playlist', 'weplugins_filter_post_playlist', 10, 3 );Need customization or have any questions? Feel free to Contact Us.
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.