[Resolved] How to add code to hook in child theme functions.php

Home Forums Support How to add code to hook in child theme functions.php

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #275198
    Hans Christian Siller

    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!

    #275338
    Tom
    Lead Developer
    Lead Developer

    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 } 
    }
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.