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.
Example 1: Modifying Image Caption Shortcode
In this example, we’ll create a function to modify the default caption shortcode and then register it using add_filter
.
function weplugins_modify_image_add_caption_shortcode_defaults($shcode, $html) { // Modify the $shcode variable as per your requirements and return it. return $shcode; } // Add the filter add_filter( "image_add_caption_shortcode", "weplugins_modify_image_add_caption_shortcode_defaults", 10, 2 );
Example 2: Removing a Hook Callback
If you ever need to remove a registered hook, like in this example, you can use remove_filter
to unregister your function.
remove_filter( "image_add_caption_shortcode", "weplugins_modify_image_add_caption_shortcode_defaults", 10, 2 );
Remember to use the same callback function name, priority, and number of arguments when removing the hook callback.
Example 3: Applying the Filter
Here’s how you can apply the filter directly.
apply_filters( 'image_add_caption_shortcode', string $shcode, string $html );
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.