Support

Account

Home Forums ACF PRO How to include huge ACF Fields with the_content?

Helping

How to include huge ACF Fields with the_content?

  • I’m using huge ACF fields with global posts. Most of the fields are Text, taxonomies & repeater. First time, I put ACF codes in single.php file after the_content. I saw that all post goes after the defaults contents.
    Then, I put all ACF codes in function.php using following codes:

    add_filter( 'the_content', 'my_the_content_filter', 0 );
    function my_the_content_filter( $content ) {
    if (is_single()) {
    global $post;
    $pgLnk=get_post_meta($post->ID, 'Button', true);
    ob_start();
    ?>
    <!– #ACF Start–>
    <table>
    <thead>
    <tr>
    <th>Personal Information</th>
    </tr>
    </thead>
    <tbody>
    
    <?php if( get_field('celebs_current_status') == 'Death' ): ?>
    <tr>
    <td>Died</td>
    <td><?php the_field( 'death_date_&_reason' ); ?></td>
    </tr>
    <?php // layout_2
    elseif( get_field('celebs_current_status') == 'Alive' ): ?>
    <tr>
    <td>Date of Birth</td>
    <td><?php the_field( 'date_of_birth' ); ?></td>
    </tr>
    <tr>
    <td>Religion</td>
    <td><?php $religion_terms = get_field( 'religion' ); ?>
    <?php if ( $religion_terms ): ?>
    <?php foreach ( $religion_terms as $religion_term ): ?>
    “><?php echo $religion_term->name; ?>
    <?php endforeach; ?>
    <?php endif; ?></td>
    </tr>
    <?php
    
    if( have_rows('celebs_gender') ):
    
    while( have_rows('celebs_gender') ) : the_row();
    
    // get layout
    $layout = get_row_layout();
    
    // layout_1
    if( $layout === 'female_celebs' ): ?>
    <div class="female_celebs">
    <tr>
    <td>Gender:</td>
    <td><?php the_sub_field( 'gender_female' ); ?></td>
    </tr>
    <?php // layout_2
    elseif( $layout === 'male_celebs' ): ?>
    <div class="male_celebs">
    <tr>
    <td>Genter:</td>
    <td><?php the_sub_field( 'gender_male' ); ?></td>
    </tr>
    <?php endif;
    
    endwhile;
    
    endif;
    
    ?>
    
    </tbody>
    </table>
    <!–2nd Image –>
    <div align="center">
    <?php
    
    $image = get_field('2nd_image');
    
    if( !empty($image) ):
    
    // vars
    $url = $image['url'];
    $title = $image['title'];
    $alt = $image['alt'];
    $caption = $image['caption'];
    
    // thumbnail
    $size = 'medium';
    $thumb = $image['sizes'][ $size ];
    $width = $image['sizes'][ $size . '-width' ];
    $height = $image['sizes'][ $size . '-height' ];
    
    if( $caption ): ?>
    
    <div class="wp-caption">
    
    <?php endif; ?>
    
    "title="<?php echo $title; ?>">
    
     "alt="<?php echo $alt; ?>"width="<?php echo $width; ?>"height="<?php echo $height; ?>"/>
    
    <?php if( $caption ): ?>
    
    <p class="wp-caption-text"><?php echo $caption; ?></p>
    
    </div>
    
    <?php endif; ?>
    
    <?php endif; ?>
    </div>
    <!– Career (Repeater Fields –>
    <h3 class="career"><span>Career at a Glance</span></h3>
    <?php if(get_field('career_fields')): ?>
    
    <?php while(has_sub_field('career_fields')): ?>
    <?php the_sub_field('career_item'); ?>: <?php the_sub_field('career_value'); ?>
    <?php endwhile; ?>
    <?php endif; ?>
    ?>
    <!– #ACF End–>
    <?php
    $content .= ob_get_clean();
    }
    return $content;
    }

    Now, it’s showing properly. But, I’m confused that is search engine bot will indexed or not? Or, is there any option to improve the codes?

  • Search engines, like google will index anything that appears on your page. Since your not actually using the content in the standard WP editor, most people would probably just edit the page/post template to replace the standard the_content() call in WP with what you are doing. But a filter on the_content will have the same result, plus it has the benefit of working without altering the template file if there’s a reason it should not be changed.

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

The topic ‘How to include huge ACF Fields with the_content?’ is closed to new replies.