- This topic has 5 replies, 2 voices, and was last updated 4 years, 9 months ago by Tom.
-
AuthorPosts
-
June 12, 2019 at 8:25 am #927173Dan
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
DanJune 12, 2019 at 4:05 pm #927610TomLead DeveloperLead DeveloperHi 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 ๐
June 13, 2019 at 1:05 pm #928810DanThanks 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!
DanJune 13, 2019 at 3:00 pm #928922TomLead DeveloperLead DeveloperInstead 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.June 13, 2019 at 3:24 pm #928930DanThanks Tom, will give it a try
Dan
June 13, 2019 at 3:27 pm #928932TomLead DeveloperLead DeveloperNo problem ๐
-
AuthorPosts
- You must be logged in to reply to this topic.