[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
    Posts
  • #927173

    Dan

    I saw the answer here:
    https://generatepress.com/forums/reply/628469/

    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?

    Thanks
    Dan

    #927610

    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">
                    %3$s
                </div>
            </div>',
            trim( $options['container_classes'] ),
            trim( $options['inner_container_classes'] ),
            $options['content']
        );
    }, 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 🙂

    #928810

    Dan

    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">
                 <h3>
    					 <?php
            $parent_link = get_permalink($post->post_parent);
            $parent_title = get_the_title($post->post_parent);
             
            echo '<a href="' .$parent_link .'">' . $parent_title.  '</a>'; ?>
    			</h3>
    <?php // list child pages of current page
    if($post->post_parent)
    $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) { ?>
    <ul>
    <?php echo $children; ?>
     <?php } ?>
    </ul>
    </div>
    <?php } ?>
          
            
    	</div>
       		

    Thanks in advance!
    Dan

    #928922

    Tom Lead Developer

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

    add_shortcode( 'your_shortcode_name', function() {
        ob_start();
        ?>
             Your code in here
        <?php
        return ob_get_clean();
    } );

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

    #928930

    Dan

    Thanks Tom, will give it a try

    Dan

    #928932

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

You must be logged in to reply to this topic.