Guest User

Untitled

a guest
Dec 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. <?php
  2.  
  3. function replace_thumbnail( $id, $object_id, $meta_key ) {
  4.  
  5. if ( '_thumbnail_id' === $meta_key && 'post' === get_post_type( $object_id ) ) {
  6. remove_filter( 'get_post_metadata', __FUNCTION__ );
  7.  
  8. $default_id_img = 91;
  9.  
  10. $id = has_post_thumbnail( $object_id ) ? $id : $default_id_img;
  11.  
  12. add_filter( 'get_post_metadata', __FUNCTION__, 10, 4 );
  13. }
  14.  
  15. return $id;
  16. }
  17.  
  18. add_filter( 'get_post_metadata', 'replace_thumbnail', 10, 3 );
Add Comment
Please, Sign In to add comment