Advertisement
Guest User

Sarah AMP Contents-Module filter

a guest
Apr 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2.  
  3. if (! defined( 'ABSPATH') ){
  4.   exit;
  5. }
  6.  
  7.  
  8. add_filter('ampforwp_pb_cntmod_rawhtml', 'sarah_ampforwp_pb_cntmod_rawhtml');
  9.  
  10.  
  11. function sarah_ampforwp_pb_cntmod_rawhtml($rawhtml){
  12.   $format = get_post_format();
  13.   $category = get_the_category();
  14.     if(is_array($category) && count($category) > 0){
  15.       $category = $category[0]->name;
  16.     }
  17.     $rawhtml = str_replace(array(
  18.         "{{category}}",
  19.         "{{format}}"
  20.     ),
  21.     array(
  22.     $category,
  23.     $format,
  24.     ),
  25.     );
  26.     $rawhtml = ampforwp_replaceIfContentConditional("category", $category, $rawhtml);
  27.     $rawhtml = ampforwp_replaceIfContentConditional("format", $format, $rawhtml);
  28. }
  29.  
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement