Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Post categories partial
- *
- * Used when "Classic Enhanced" masonry style is selected.
- *
- * @version 10.5
- */
- // Exit if accessed directly
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- global $post;
- echo '<span class="meta-category">';
- $categories = get_the_category();
- if ( class_exists('WPSEO_Primary_Term') ) {
- $wpseo_primary_term = new WPSEO_Primary_Term( 'category', get_the_id() );
- $wpseo_primary_term = $wpseo_primary_term->get_primary_term();
- $term = get_term( $wpseo_primary_term );
- if( !is_wp_error($term) ) {
- $category_display = $term->name;
- $category_slug = $term->slug;
- echo '<a href="'.$category_slug.'">'.$category_display.'</a></span>';
- return;
- }
- }
- if ( ! empty( $categories ) ) {
- $output = null;
- foreach ( $categories as $category ) {
- $output .= '<a class="' . esc_attr( $category->slug ) . '" href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a>';
- }
- echo trim( $output ); // WPCS: XSS ok.
- }
- echo '</span>';
Advertisement
Add Comment
Please, Sign In to add comment