Created
May 6, 2026 06:25
-
-
Save chikaibeneme/3859094fe7aabd62cc9d1215a87b7481 to your computer and use it in GitHub Desktop.
script for kadence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function kt_get_aioseo_primary_category( $post_id = 0 ) { | |
| $post_id = $post_id ? absint( $post_id ) : get_the_ID(); | |
| if ( ! $post_id ) { | |
| return false; | |
| } | |
| if ( function_exists( 'aioseo' ) ) { | |
| $aioseo = aioseo(); | |
| if ( | |
| isset( $aioseo->standalone->primaryTerm ) && | |
| is_callable( array( $aioseo->standalone->primaryTerm, 'getPrimaryTerm' ) ) | |
| ) { | |
| $primary_term = $aioseo->standalone->primaryTerm->getPrimaryTerm( $post_id, 'category' ); | |
| if ( $primary_term instanceof WP_Term && ! is_wp_error( $primary_term ) ) { | |
| return $primary_term; | |
| } | |
| } | |
| } | |
| $categories = get_the_terms( $post_id, 'category' ); | |
| if ( ! empty( $categories ) && ! is_wp_error( $categories ) ) { | |
| return array_shift( $categories ); | |
| } | |
| return false; | |
| } | |
| function kt_main_category_only() { | |
| $category = kt_get_aioseo_primary_category(); | |
| if ( ! $category ) { | |
| return; | |
| } | |
| $cat_link = get_term_link( $category ); | |
| if ( is_wp_error( $cat_link ) ) { | |
| return; | |
| } | |
| ?> | |
| <div class="entry-taxonomies"> | |
| <span class="category-links"> | |
| <a href="<?php echo esc_url( $cat_link ); ?>" rel="category tag"><?php echo esc_html( $category->name ); ?></a> | |
| </span> | |
| </div> | |
| <?php | |
| } | |
| function kt_show_only_aioseo_main_category() { | |
| remove_action( 'kadence_loop_entry_header', 'Kadence\loop_entry_taxonomies', 10 ); | |
| add_action( 'kadence_single_before_entry_title', 'kt_main_category_only', 5 ); | |
| add_action( 'kadence_loop_entry_header', 'kt_main_category_only', 10 ); | |
| } | |
| add_action( 'wp', 'kt_show_only_aioseo_main_category' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment