Archived topic
Shortcodes on pagehero headers
6 replies · Started by johnaps on April 6, 2020
Hello!
I ve tried
function db_page_hero_excerpt() {
ob_start();
global $post;
if ( has_excerpt( $post->ID ) ) {
?>
<div class="page-hero-excerpt">
<?php echo the_excerpt(); ?>
</div>
<?php
}
return ob_get_clean();
}
add_shortcode( 'page_hero_excerpt','db_page_hero_excerpt' );
To get category description on my category pages but i dont get nothing.
Also on author archive pages i have added a shortcode from a plugin for the author box and it doesnt work
http://thefinterestcom.kinsta.cloud/author/johnitos/
Any idea why? As i have seen in other threads shortcodes should work right?
Hi there,
For it to work on your category pages, you'll need to use term_description(); instead of the_excerpt(): https://developer.wordpress.org/reference/functions/term_description/
Let me know :)
Hey Tom! I made the code as it follows based on your advice
function db_page_hero_excerpt() {
ob_start();
global $post;
if ( has_excerpt( $post->ID ) ) {
?>
<div class="page-hero-excerpt">
<?php echo term_description(); ?>
</div>
<?php
}
return ob_get_clean();
}
add_shortcode( 'page_hero_excerpt','db_page_hero_excerpt' );
But i still dont get category desription to show...
Also you didnt tell me why simple shortcodes generated by a plugin (simple author box) arent working on pagehero header...?
Try this:
function db_page_hero_excerpt() {
ob_start();
?>
<div class="page-hero-excerpt">
<?php echo term_description(); ?>
</div>
<?php
return ob_get_clean();
}
add_shortcode( 'page_hero_excerpt','db_page_hero_excerpt' );
Can you share the author shortcode you're using?
Thank you for the code it worked! :)
Simple Author Box i am using!
shortcode = [simple-author-box]
test page = thefinterestcom.kinsta.cloud/author/johnitos/
Fixed it! Thank you for all your help :)
No problem :)