Guest User

Untitled

a guest
Oct 12th, 2022
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2. /**
  3. * Post categories partial
  4. *
  5. * Used when "Classic Enhanced" masonry style is selected.
  6. *
  7. * @version 10.5
  8. */
  9.  
  10. // Exit if accessed directly
  11. if ( ! defined( 'ABSPATH' ) ) {
  12.   exit;
  13. }
  14.  
  15. global $post;
  16.  
  17. echo '<span class="meta-category">';
  18.  
  19. $categories = get_the_category();
  20.  
  21. if ( class_exists('WPSEO_Primary_Term') ) {
  22.   $wpseo_primary_term = new WPSEO_Primary_Term( 'category', get_the_id() );
  23.     $wpseo_primary_term = $wpseo_primary_term->get_primary_term();
  24.     $term = get_term( $wpseo_primary_term );
  25.  
  26.   if( !is_wp_error($term) ) {
  27.     $category_display = $term->name;
  28.     $category_slug = $term->slug;
  29.     echo '<a href="'.$category_slug.'">'.$category_display.'</a></span>';
  30.     return;
  31.   }
  32.  
  33. }
  34.  
  35. if ( ! empty( $categories ) ) {
  36.   $output = null;
  37.   foreach ( $categories as $category ) {
  38.     $output .= '<a class="' . esc_attr( $category->slug ) . '" href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a>';
  39.   }
  40.   echo trim( $output ); // WPCS: XSS ok.
  41. }
  42.  
  43. echo '</span>';
Advertisement
Add Comment
Please, Sign In to add comment