0

Im building a website with wordpress, using a child theme. there is a file in the main theme folders, called entry.php that is where I need to add a bit of php at the bottom of this document.

I don't want to touch the parent theme files, to avoid problems when I update the theme.

How can I embed/insert PHP code in that specific file/ part of the code?

Is this done using filters? embed? can you please guide me I have been searching in google but I dont know if im using the right keywords to search.

Im learning php and this would be of great help :)

Further details:

Ideally I want this bit of code to be embedded right before the end of the "/section"

<?php if (in_category('3')) { ?>

<div class="recommended-bottom">

    <h3 class="recommended-title">WRITING</h3>
    <?php echo do_shortcode('[pt_view id="343aa4f4c3"]');?>
        </div>

<?php }else { ?>
<?php } ?>

The code in entry.php is:

<article <?php post_class(); if( ! is_single() ) echo ' itemprop="blogPost"'; ?> itemscope itemtype="http://schema.org/BlogPosting">

    <?php shiroi_get_post_view( 'parts/header', get_post_format() ); ?>
    <?php shiroi_get_post_view( 'media/media', get_post_format() ); ?>

    <section class="entry-content post-content" itemprop="articleBody">

        <?php do_action( 'shiroi_before_post_body_content' );

        if( is_single() || 'the_content' === shiroi_get_option( 'blog_summary' ) ) : 
            the_content( __( 'Continue Reading', 'shiroi' ) );
        else:
            the_excerpt();
            printf( '<div class="more-link-wrap"><a href="%s" class="more-link">%s</a></div>', esc_url( get_permalink() ), esc_html__( 'Continue Reading', 'shiroi' ) );
        endif;

        if( is_single() ):
            if( get_the_tags() && shiroi_get_option( 'blog_show_tags' ) ):

            ?><p class="post-tags">
                <?php the_tags( '<i class="fa fa-tags"></i>', ', ' ); ?>
            </p>
            <?php endif;

            wp_link_pages(array(
                'before' => '<nav class="entries-page-nav"><ul>', 
                'after' => '</ul></nav>', 
                'separator' => '', 
                'pagelink' => '<span class="entries-page-nav-item">%</span>'
            ));
        endif;

        do_action( 'shiroi_after_post_body_content' ); ?>




    </section>

    <?php if( is_single() ) : 
        shiroi_get_post_view( 'parts/footer', get_post_format() );
        shiroi_get_post_view( 'parts/comments', get_post_format() );
    endif; ?>


</article>

1 Answer 1

1

If that is the sum of the code for that file then the only place near the bottom is that do_action-- do_action( 'shiroi_after_post_body_content' );-- which looks to be what you want.

function test_new_action() {
  echo 'Howdy';
}
add_action('shiroi_after_post_body_content','test_new_action');

Depending upon how this file is included there might be other hooks.

You can't add code to the file otherwise without editing it manually or with PHP

For reference (maybe helpful): https://wordpress.stackexchange.com/a/97599/21376

1
  • THANKS this was very helpful. I have learned a lot today. I will continue using Hooks and replace my previous dirty "theme hacks..."
    – dmtnexer
    Commented Mar 27, 2015 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.