Site logo

Archived topic

How to add code to hook in child theme functions.php

1 reply · Started by Hans Christian Siller on February 6, 2017

Viewing posts 1–2 of 2

Hi,

I have to insert content blocks in many different places (some on all single pages/posts, some only on some custom post types) - so I thought doing that via the predefined gp hooks and to define all the conditional statements inside my child theme functions.php (because the code will be long and wont fit well into the hooks fields in the GP Hooks interface).

I know this must be trivial, but I always kill my wordpress install when trying to do this :(
(white screen of death)

I have added this to my funtions.php

// insert Image credit into all single posts, events, pages etc
add_action( 'generate_after_entry_content', 'add_imgcredit' );
function add_imgcredit(){
    if ( is_singular() ) {<div class="imagecredits"><?php the_field('image_credits'); ?></div>} 
}

ps. I have used Advanced Custom Fields to set up the extra fields...

Any tips on how to do this correctly? Thanks!

You're close! You're adding your HTML within the function without closing PHP first, so it's causing a PHP error.

Try this:

add_action( 'generate_after_entry_content', 'add_imgcredit' );
function add_imgcredit(){
    if ( is_singular() ) { ?>
        <div class="imagecredits"><?php the_field('image_credits'); ?></div>
    <?php } 
}
This archived topic is closed to new replies.