WordPress custom fields outside html labels

I’ve created a custom field with Advanced Custom Fields plugin called ‘colaboradores’ with fields logo (image), direccion (string) and mapa (image);

In archive-colaboradores.php, I call the WP_Quer. In short, code is:

Read More
<?php
    $args = array(
        'post_type' => 'colaboradores',
        'pagination' => false
    ); ?>

    <?php $the_query = new WP_Query( $args ); ?>

    <?php while ( have_posts() ) : the_post(); ?>

        <?php get_template_part( 'content', 'colaboradores' ); ?>

    <?php endwhile; // end of the loop. ?>

So in content-colaboradores.php I show my custom fields with the_field():

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<h1 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1>

<?php $image = get_field( 'logo' ); ?>
<?php echo '<img src="' . $image['url'] . '" >'; ?>

<?php echo '<p>' . the_field('direccion') . '</p>'; ?>

<?php $image = get_field( 'mapa' ); ?>
<?php echo '<img src="' . $image['url'] . '" >'; ?>

</article><!-- #post-## -->

Everything is fine except direccion, which is always outside the

tag checking with Google Chrome:

<img src="https://i.stack.imgur.com/3ogWP.jpg" alt="address is outside the

tags”>

I’ve removed all the code previous to ‘ . the_field(‘direccion’) . ‘

‘; ?> but the problem persists.

Do you know why is it hapening? Thanks.

Related posts

1 comment

  1. I cant be certain as dev tools doesnt show anything out of the ordinary but maybe try wrapping the_field in some tags to make sure nothing out of the ordinary is coming through.

    <?php echo '<p>' . strip_tags(trim(the_field('direccion'))) . '</p>'; ?>

    I put the strip tags in there because thats normally why chrome and other browsers would put content outside of an inline tag like a p tag

    Other than that, maybe try letting wordpress format the paragraph tags, and see if it runs then

    <?php echo apply_filters("the_content",get_field('direccion')); ?>

    See if either of them work?

Comments are closed.