Site logo

Archived topic

Shortcodes on pagehero headers

6 replies · Started by johnaps on April 6, 2020

Viewing posts 1–7 of 7

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?

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 :)

This archived topic is closed to new replies.