Support

Account

Home Forums General Issues Assign Custom Fields to Post Excerpt Reply To: Assign Custom Fields to Post Excerpt

  • It should be possible by simply modifying the template file that displays your home page, and that is best done in a Child Theme unless your Theme is completely custom and you don’t have to worry about template files being overwritten by Theme updates.

    SO first identify your Child Theme’s home page template (many themes use different names such as homepage.php, frontpage.php, or even index.php – you’ll have to figure out which one it is, if you’re having trouble way at the bottom I have a snippet you can add that tells you which template file is being used on any page).

    Then find the spot in the template where the_excerpt(); appears – MANY newer Themes use a ‘content’ loop so the template MAY refer you to another template (part) like this:

    get_template_part( 'content','specific-content-type' );

    If it does then open up that content file and look for the_excerpt(); there.

    Then all you have to do is insert your custom field variables either before or after the excerpt, or even replace the excerpt with your custom field data if you don’t want to use an actual excerpt (say for a short product description, which you can either pull from the_content(); or use the actual excerpt field on the Post Edit screen, if it’s not showing make sure it’s checked under “Screen Options” at the top of the page)

    If you need help in how to add your custom field data to the template, let me know and I can give you some code.

    — IF YOU CAN’T figure out what template file is being used, add THIS CODE to your Child Theme’s functions.php file OR your own custom plugin, you can comment it out or uncomment as necessary, or just leave it uncommented all the time – this will ONLY display the template file used IF you are a logged-in Admin-level user, it shows at the TOP of the page above the header the path & file name:

    // Debug function to show the name of the current template being used
      function show_template() {
        if ( current_user_can( 'create_users' ) ) {
          global $template;
          print_r($template);
      	}
       }
      add_action('wp_head', 'show_template');