Archived topic
File edits and Child Theme
7 replies · Started by Aleksey on October 22, 2020
Hi!
I've editied post-meta.php here "generatepress\inc\structure" to add author box inside <footer> tag. To save this edit from deleting during further updates I've created the same folders in the child theme and copied my new post-meta.php there. But unfortunately, edits don't show on the website.
How can I make this changes work with child theme?
Hi,
I believe this can be done w/ just filters and hooks instead of creating a post-meta.php.
Something like this:
add_filter('generate_before_footer_content', function(){
//your author box code here
});
Simply add this code to your child theme's functions.php.
If you want to place it somewhere else, you can replace the hook w/ any hooks found here:
https://docs.generatepress.com/article/hooks-visual-guide/
Thanks for a quick reply. Somehow this code:
add_filter('generate_after_entry_content', function() {
<strong><div class="author-box"></strong>
<?php global $post; ?>
<div class="avatar"><?php echo get_avatar ( get_the_author_meta( 'ID' )); ?></div>
<div class="author-title" itemprop="author" itemscope itemtype="http://schema.org/Person">
<span itemprop="name"><?php printf( get_the_author_meta( 'display_name') );?></span>
</div>
<div class="author-summary">
<p class="author-description"><?php echo nl2br( get_the_author_meta( 'description' ), null ); ?></p>
</div>
</div>
});
doesn't want to work.
syntax error, unexpected '<'
for bolded line.
Hi there,
you would need to use a Action Hook like so:
add_action('generate_after_entry_content', function() {
?>
// Your HTML Goes here
<?php
});
Or the simpler process is to just add your HTML to the a Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/
Thanks David, now my html works, but it puts author box outside <footer> tag: http://prntscr.com/v59gsv
How can I place it inside <footer>?
There isn't a hook inside there. Instead you would first need to unhook the footer meta:
add_action( 'wp', function() {
remove_action( 'generate_after_entry_content', 'generate_footer_meta' );
} );
Then Hook back it back in with your own content:
add_action('generate_after_entry_content', function() {
?>
<footer class="entry-meta">
// Your HTML Goes here
<?php generate_entry_meta(); ?>
</footer>
<?php
});
Brilliant! Working like a charm :)
Thank you for your help!
You're welcome