Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use post_embed_url filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 5, 2022
5 minutes read

post_embed_url filter

Filters the URL to embed a specific post.

 apply_filters( 'post_embed_url', string $embed_url, WP_Post $post ) 

 

Descrioption

This hook is used for filter the URL to embed a specific post. By using it we can fitters the embed URL for a specific post.

Parameters

  • $embed_url : (string) The post embed URL.
  • $post : (WP_Post) The corresponding post object.

Live Example

To run the hook, copy the example below.

$embed_url = apply_filters( 'post_embed_url', $embed_url, $post ); 
                         
if ( !empty( $embed_url ) ) { 
                         
   // everything has led up to this point... 
                         
} 
  
  

The following example is for adding a hook callback.

// define the post_embed_url callback 
function filter_post_embed_url( $embed_url, $post ) { 
// make filter magic happen here... 
return $embed_url; 
}; 

// add the filter 
add_filter( 'post_embed_url', 'filter_post_embed_url', 10, 2 ); 

To remove a hook callback, use the example below.

// remove the filter 
remove_filter( 'post_embed_url', 'filter_post_embed_url', 10, 2 ); 

 

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

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.