[Support request] Inside hero hook

Home Forums Support Inside hero hook

This topic contains 5 replies, has 2 voices, and was last updated by  Tom 3 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #927173


    I saw the answer here:

    I would like to add / edit items in the ‘inside-page-hero’ div with php, how can that be achieved.
    Which king of filter can be used?
    Do you have an example?



    Tom Lead Developer

    Hi there,

    For sure! You can do it like this:

    add_filter( 'generate_page_hero_output', function( $output, $options ) {
        return sprintf(
            '<div class="%1$s">
                <div class="%2$s">
            trim( $options['container_classes'] ),
            trim( $options['inner_container_classes'] ),
    }, 10, 2 );

    You can take advantage of sprintf, or just add your HTML within the <div> elements.

    Let me know if you need more info 🙂



    Thanks Tom,
    What I would like to do is this:
    If the page has a parent so instead of displaying the page title in the hero section, show the parent’s page title, and show the current page title in the content section, not in the header.
    This is the code I was using in the former site – showing the sub pages and the parent’s title.
    For the sub-pages I’m using a simple condition ‘after_header’ hook.

    	<div id="menu-sidebar" class="widget-area" role="complementary">
                <?php if ( is_page()) { ?> <div class="page-sidebar-nav">
            $parent_link = get_permalink($post->post_parent);
            $parent_title = get_the_title($post->post_parent);
            echo '<a href="' .$parent_link .'">' . $parent_title.  '</a>'; ?>
    <?php // list child pages of current page
    $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0&depth=1'); else
    $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1');
    if ($children) { ?>
    <?php echo $children; ?>
     <?php } ?>
    <?php } ?>

    Thanks in advance!


    Tom Lead Developer

    Instead of filtering the output, I would turn that code into a shortcode:

    add_shortcode( 'your_shortcode_name', function() {
             Your code in here
        return ob_get_clean();
    } );

    Then you would use the [your_shortcode_name] in your Hero content.



    Thanks Tom, will give it a try



    Tom Lead Developer
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.