• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to user navigation

PopWP

WordPress and Genesis Tutorials

  • Get Started
  • About
  • Archive
  • Services
  • Membership
  • My Account

Change default excerpt to custom post field

Last Updated on July 12, 2020 Favorited: 0 times

Tis tutorial provides the steps to change default excerpt to show custom post field. This tutorial uses the flexible content but can be work on any field.

In child-theme/functions.php, add

add_filter('the_excerpt', 'your_function_name');

function your_function_name($excerpt) {
  if( have_rows('flexible') ):
  
    while ( have_rows('flexible') ) : the_row(); 
        if( get_row_layout() == 'flexible_name' ): 
      
         $my_acf_field = wp_trim_words(get_sub_field('custom_excerpt'), 100);

         echo ''.$my_acf_field.'';
        endif;
    endwhile;
    else:
    endif;
    
}

More: https://www.advancedcustomfields.com/resources/flexible-content/

Related Posts

  • Post Grid design having the custom field in WordPress
  • Output Custom Field Value in WordPress
  • Add Video in entry content using custom fields on singular post

Categories: Free Content Tags: custom field, excerpt

Reader Interactions

Primary Sidebar

Search

WPEngine WordPress Hosting, Perfected.

Hosting You are looking for?.
Perfect solution for small business to global enterprise.

Learn more

StudioPress Genesis Theme Framework

The No.1 Theme Provider.
Creative, SEO rich Theme for all niche projects.

Learn more

Categories

  • Free Content
  • Genesis Tutorials
  • Premium Content
  • Snippets
  • What's New?
  • WordPress Tutorials

Tag Cloud

Archive Background Section blog canvas menu center logo columns conditional tags CSS CSS Grid custom Customizer custom post type Custom Post Types custom template Custom Widget effect eNews Extended Featured Image front-page Genesis Genesis Sample header right hero section Image Background js layout left menu Logo menu Navigation Menu newsletter post page related posts responsive menu search search widget Shrinking Logo site header slide in-out Stylesheet Template Utility Bar Video Background widgets WordPress

Built with Genesis Framework + WordPress by Aryan Raj

  • Contact
  • FAQ
  • Disclaimer
  • Privacy Policy
  • Copyright Policy
  • Terms of Service