Advertisement
pjeaje

How to hook/add php and html before/after category title

Jan 1st, 2015
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. // How to add/insert php/code and/or text/html before and after the single_category_title() tag in WordPress in archive.php/category.php
  2.  
  3. //
  4. // BEFORE CATEGORY TITLE
  5. //
  6.  
  7. //   *** Add Shortcode for php code before category title ***
  8. function code_before_cat_title_custom_shortcode() {
  9. // start php code
  10. return 'CODE BEFORE';
  11. // end php code
  12. }
  13. add_shortcode( 'code-before-cat-title', 'code_before_cat_title_custom_shortcode' );
  14.  
  15. // *** Insert the php code AND the html before the category title ***
  16. add_filter( 'single_cat_title', 'code_before_single_cat_title' );
  17. function code_before_single_cat_title( $text2 ) {
  18.     $append2 = '';
  19.     $append2 .=  do_shortcode('[code-before-cat-title]' );
  20.     $text2 = '</h1><p style=margin-top:-30px;>' .  $append2 . '</p><p>Some text/html can be inserted after the top code here</p><h1 class="page-title"> Performance: ' .  $text2 . '</h1><p>Some text/html can be inserted after the category title here</p>';
  21.     return $text2;
  22. }
  23.  
  24. //
  25. // AFTER CATEGORY TITLE
  26. //
  27.  
  28. // *** Add Shortcode for php code after category title ***
  29. function code_after_cat_title_custom_shortcode() {
  30. // start php code
  31. return 'CODE AFTER';
  32. // end php code
  33. }
  34. add_shortcode( 'code-after-cat-title', 'code_after_cat_title_custom_shortcode' );
  35.  
  36. // *** Insert the php code AND the html after the category title ***
  37. add_filter( 'single_cat_title', 'before_after_code_single_cat_title' );
  38. function before_after_code_single_cat_title( $text ) {
  39.     $append = '';
  40.     $append .=  do_shortcode('[code-after-cat-title]' );
  41.     $text = $text . '</h1><p>Some text/html can be inserted before the bottom code here</p>' .  $append . '<p>Some text/html can be inserted after the bottom code here</p>';
  42.     return $text;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement