Support

Account

Home Forums Backend Issues (wp-admin) Duplicate Content when using acf/render_field

Solving

Duplicate Content when using acf/render_field

  • Howdy,

    I wanted to add a button below a text field. The text field has the key:

    field_mentorship_post_object_match_volunteer

    So I added this code to hook up the function:

    
    $this->af_registration->add_action(
        'acf/render_field/key=field_mentorship_post_object_match_client',
        MentorshipHooks::class,
        'add_edit_participant_button'
    );
    

    The callback prints out the button:

    
    if ( $link !== '' && ! empty( $link ) ) : ?>
        <a class="button button-primary button-large centered-btn" href="<?php echo $link; ?>">
            Edit <?php echo ucwords( $participant_type ); ?>
        </a>
    

    All good, but the callback is printing the button twice:

    Two Buttons in Love

    Any idea why this is being called twice?

  • It’s not happening when I test it, but then I’m not using a function call to do the addition.

    The only thing I can think of from looking at your code is that this is adding the action twice for some reason

    
    $this->af_registration->add_action(...
    
  • Thanks John.

    af_registration is class from WPMUDEV which I have been using for years and it works fine. All my actions/filters are using that, so I would see 2 of everything, so who knows.

    I was very naughty and stuck the button inside a div and hid the second one with a CSS rule 🙈

    
    .btn-container {
        &:last-child {
            display: none;
        }
    }
    
  • Is it possible that the code where you’re adding the action could be running twice somehow?

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.