Support

Account

Home Forums ACF PRO How to show a custom field directly after each title on archive page

Helping

How to show a custom field directly after each title on archive page

  • Hi guys,

    I want to hook in two acf fields directly after each post title in archive.php (not changing the archive template itself). I find out I have to add a do_action in my functions.php.

    This is the situation it is on archive pages:
    – Title
    – Excerpt

    This is the situation I need on archive pages:
    – Title
    – Price –> acf field = price
    – Slogan –> acf field = short_pay_off
    – Exerpt

    Because I’m not a programmer I really don’t know where to begin. The closest snippet I found was this one:

    add_action( 'genesis_entry_content', 'function_name', 12 );
    function function_name() {
        $value = get_post_meta( get_the_ID(), 'price', true );
        
        if ( ! empty( $value ) ) {
        
        echo '<div class="price">'. $value .'</div>';
        
        }
    }
    genesis();

    Problem is that I don’t use genesis but avada and that I don’t know how to add a second acf field in the snippet above. Plus I also believe I have to add an extra piece of code to let this snippet work within functions.php. Something like this

    if ( ! class_exists( 'acf' ) ) 
        return;

    But I don’t know where to place it in the snippet above.

    Is there someone who wants to help me out?
    Thanks in advance.

  • First of all that is for genesis and your using avada, the two themes will have different hooks. You will need to figure out what hook is available in avada to insert content between the title and the excerpt. I can’t help you with that and you need to look at the avada documentation to see if it’s possible or contact avada support to get that answer. Once you figure out the correct hook to use then you edit the functions.php file for your theme to add the code you want to run for the action.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.