WPIntell

Source evidence

Category title doesnt show year in shortcode [year]

Dynamic Month & Year into Posts · support · 2024-02-26T14:22:00+00:00

mixedsentiment
mediumseverity
0.84relevance
13replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

5 / 34 rows with source links

14.7% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

29 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
buldog52 resolved
Dear stuff. After last updating of plugin I got a problem. Plugin doesnt work with category titles WP 6.3 Dynamic Month & Year into Posts Version 1.3.5 Best regards, Leonid This topic was modified 2 years, 3 months ago by buldog52 . The page I need help with: [ log in to see the link] Looks like this has something to do with the Theme (or page builder) that you are using. Can you tell me which theme should I install to test it out? Wait, I was able to reproduce the issue. Releasing a fix now. Hi @buldog52 , I have released an update. Please update to 1.3.6 and let me know how this works for you. Dear Gaurav Tiwari, I updated plugin to Version 1.3.6 But category title doesnt show year in shortcode [year] You can see it here https://cs2-bettings.com/cs2-case-opening-sites Website using custom theme (html + css + js) I use such code <?php $this_title = ""; if (is_page()) { $this_title = get_the_title( $page_id ); } if (is_category()) { $cat_id = preg_replace('/\D+/', '', $page_id); $this_title = get_cat_name( $cat_id ); } ?> <h1><?php echo $this_title; ?></h1> This reply was modified 2 years, 3 months ago by buldog52 . This reply was modified 2 years, 3 months ago by buldog52 . Hello again I changed code <h1><?php echo apply_filters( 'the_title', $this_title ); ?></h1> And now category shows year [year]. You can see it here https://cs2-bettings.com/cs2-case-opening-sites But I use the title of category (with [year]) in many places, for example in breadcrumbs, and I will need do some job to solve problem. I have such problem on post page https://cs2-bettings.com/is-howl-gg-legit I see. Can you please share the PHP code for the Breadcrumb and also that of Table of Contents that you have on right? Dear Gaurav Tiwari I use yoast seo breadcrumbs with some custom code //This function return primary category for posts (works only with Yoast Seo) function get_post_primary_category($post_id, $term='product_category', $return_all_categories=false){ $return = array(); if (class_exists('WPSEO_Primary_Term')){ // Show Primary category by Yoast if it is enabled & set $wpseo_primary_term = new WPSEO_Primary_Term( $term, $post_id ); $primary_term = get_term($wpseo_primary_term->get_primary_term()); if (!is_wp_error($primary_term)){ $return['primary_category'] = $primary_term; } } if (empty($return['primary_category']) || $return_all_categories){ $categories_list = get_the_terms($post_id, $term); if (empty($return['primary_category']) && !empty($categories_list)){ $return['primary_category'] = $categories_list[0]; //get the first category } if ($return_all_categories){ $return['all_categories'] = array(); if (!empty($categories_list)){ foreach($categories_list as &$category){ $return['all_categories'][] = $category->term_id; } } } } return $return; } //crumbs add_filter( 'wpseo_breadcrumb_links', 'qr_add_breadcrumb' ); function qr_add_breadcrumb( $links ) { if ( is_singular( 'post' ) ) { $post_id = get_the_ID(); //page number Blog for English language unset($links[1]); //remove the last element $breadcrumb[] = array( 'url' => get_permalink( $post_id ), 'text' => get_the_title( $post_id ), 'allow_html' => '1', ); $post_categories = get_post_primary_category(get_the_ID(), 'category'); $terms = $post_categories['primary_category']; if (get_field('category_short_name', 'category_'.$terms->term_id)) { $cat_title = get_field('category_short_name', 'category_'.$terms->term_id); } else { $cat_title = $terms->name; } $breadcrumb[] = array( 'url' => "/".$terms->slug."/", 'text' => $cat_title, 'allow_html' => '1', ); // Use array_reverse to change the order of elements in the array $reversedArray = array_reverse($breadcrumb); // Use array_map to apply array_reverse to each subarray $reversedArray = array_map('array_reverse', $reversedArray); // Add an element to the associative array of links array_splice( $links, $offset = 1, $length = 0, $reversedArray ); } return $links; } This reply was modified 2 years, 3 months ago by buldog52 . Can you try changing the if (get_field('category_short_name', 'category_'.$terms->term_id)) { $cat_title = get_field('category_short_name', 'category_'.$terms->term_id); } else { $cat_title = $terms->name; } with: if (get_field('category_short_name', 'category_'.$terms->term_id)) { $cat_title = do_shortcode(get_field('category_short_name', 'category_'.$terms->term_id)); } else { $cat_title = do_shortcode($terms->name); } (This is in //crumbs part.) In the code on the right side first line – php code, who write category name. Othe links – JavaScript reads h2 tags, that were formed on by php (acf). It seems here https://cs2-bettings.com/cs2-coinflip on right right side menu menu I need add same code for 1st item om menu <?php echo apply_filters( 'the_title', $this_title ); ?> This reply was modified 2 years, 3 months ago by buldog52 . This reply was modified 2 years, 3 months ago by buldog52 . In the code on the right side first line – php code, who write category name. Can you share the exact code, please? Edit: I see that has been fixed too. 🙂 Well done. This reply was modified 2 years, 3 months ago by Gaurav Tiwari . Thanks for your help. Now I show category title as do_shortcode(‘category_title’); Breadcrumbs works too This reply was modified 2 years, 3 months ago by buldog52 . It’s been my pleasure. Be sure to open a new thread if something else occurs. All Shortcodes are listed here: https://gauravtiwari.org/snippet/dynamic-month-year/#shortcodes

Comments

13 shown
Gaurav Tiwari 2024-02-26T14:30:00+00:00

Looks like this has something to do with the Theme (or page builder) that you are using. Can you tell me which theme should I install to test it out?

Gaurav Tiwari 2024-02-26T14:34:00+00:00

Wait, I was able to reproduce the issue. Releasing a fix now.

Gaurav Tiwari 2024-02-26T14:54:00+00:00

Hi @buldog52 , I have released an update. Please update to 1.3.6 and let me know how this works for you.

buldog52 2024-02-26T19:48:00+00:00

Dear Gaurav Tiwari, I updated plugin to Version 1.3.6 But category title doesnt show year in shortcode [year] You can see it here https://cs2-bettings.com/cs2-case-opening-sites Website using custom theme (html + css + js) I use such code <?php $this_title = ""; if (is_page()) { $this_title = get_the_title( $page_id ); } if (is_category()) { $cat_id = preg_replace('/\D+/', '', $page_id); $this_title = get_cat_name( $cat_id ); } ?> <h1><?php echo $this_title; ?></h1> This reply was modified 2 years, 3 months ago by buldog52 . This reply was modified 2 years, 3 months ago by buldog52 .

buldog52 2024-02-27T08:56:00+00:00

Hello again I changed code <h1><?php echo apply_filters( 'the_title', $this_title ); ?></h1> And now category shows year [year]. You can see it here https://cs2-bettings.com/cs2-case-opening-sites

buldog52 2024-02-27T09:10:00+00:00

But I use the title of category (with [year]) in many places, for example in breadcrumbs, and I will need do some job to solve problem. I have such problem on post page https://cs2-bettings.com/is-howl-gg-legit

Gaurav Tiwari 2024-02-27T09:19:00+00:00

I see. Can you please share the PHP code for the Breadcrumb and also that of Table of Contents that you have on right?

buldog52 2024-02-27T09:26:00+00:00

Dear Gaurav Tiwari I use yoast seo breadcrumbs with some custom code //This function return primary category for posts (works only with Yoast Seo) function get_post_primary_category($post_id, $term='product_category', $return_all_categories=false){ $return = array(); if (class_exists('WPSEO_Primary_Term')){ // Show Primary category by Yoast if it is enabled & set $wpseo_primary_term = new WPSEO_Primary_Term( $term, $post_id ); $primary_term = get_term($wpseo_primary_term->get_primary_term()); if (!is_wp_error($primary_term)){ $return['primary_category'] = $primary_term; } } if (empty($return['primary_category']) || $return_all_categories){ $categories_list = get_the_terms($post_id, $term); if (empty($return['primary_category']) && !empty($categories_list)){ $return['primary_category'] = $categories_list[0]; //get the first category } if ($return_all_categories){ $return['all_categories'] = array(); if (!empty($categories_list)){ foreach($categories_list as &$category){ $return['all_categories'][] = $category->term_id; } } } } return $return; } //crumbs add_filter( 'wpseo_breadcrumb_links', 'qr_add_breadcrumb' ); function qr_add_breadcrumb( $links ) { if ( is_singular( 'post' ) ) { $post_id = get_the_ID(); //page number Blog for English language unset($links[1]); //remove the last element $breadcrumb[] = array( 'url' => get_permalink( $post_id ), 'text' => get_the_title( $post_id ), 'allow_html' => '1', ); $post_categories = get_post_primary_category(get_the_ID(), 'category'); $terms = $post_categories['primary_category']; if (get_field('category_short_name', 'category_'.$terms->term_id)) { $cat_title = get_field('category_short_name', 'category_'.$terms->term_id); } else { $cat_title = $terms->name; } $breadcrumb[] = array( 'url' => "/".$terms->slug."/", 'text' => $cat_title, 'allow_html' => '1', ); // Use array_reverse to change the order of elements in the array $reversedArray = array_reverse($breadcrumb); // Use array_map to apply array_reverse to each subarray $reversedArray = array_map('array_reverse', $reversedArray); // Add an element to the associative array of links array_splice( $links, $offset = 1, $length = 0, $reversedArray ); } return $links; } This reply was modified 2 years, 3 months ago by buldog52 .

Gaurav Tiwari 2024-02-27T09:36:00+00:00

Can you try changing the if (get_field('category_short_name', 'category_'.$terms->term_id)) { $cat_title = get_field('category_short_name', 'category_'.$terms->term_id); } else { $cat_title = $terms->name; } with: if (get_field('category_short_name', 'category_'.$terms->term_id)) { $cat_title = do_shortcode(get_field('category_short_name', 'category_'.$terms->term_id)); } else { $cat_title = do_shortcode($terms->name); } (This is in //crumbs part.)

buldog52 2024-02-27T09:39:00+00:00

In the code on the right side first line – php code, who write category name. Othe links – JavaScript reads h2 tags, that were formed on by php (acf). It seems here https://cs2-bettings.com/cs2-coinflip on right right side menu menu I need add same code for 1st item om menu <?php echo apply_filters( 'the_title', $this_title ); ?> This reply was modified 2 years, 3 months ago by buldog52 . This reply was modified 2 years, 3 months ago by buldog52 .

Gaurav Tiwari 2024-02-27T09:55:00+00:00

In the code on the right side first line – php code, who write category name. Can you share the exact code, please? Edit: I see that has been fixed too. 🙂 Well done. This reply was modified 2 years, 3 months ago by Gaurav Tiwari .

buldog52 2024-02-27T10:00:00+00:00

Thanks for your help. Now I show category title as do_shortcode(‘category_title’); Breadcrumbs works too This reply was modified 2 years, 3 months ago by buldog52 .

Gaurav Tiwari 2024-02-27T10:03:00+00:00

It’s been my pleasure. Be sure to open a new thread if something else occurs. All Shortcodes are listed here: https://gauravtiwari.org/snippet/dynamic-month-year/#shortcodes