Categories
WordPress Tutorials

Add category text field after posts

Video for the tutorial

This should work on any Genesis Framework theme, as it uses a core hook to display the text.

Plugins Used:

  • ACF (advanced custom fields) – Free
  • Genesis Simple Hooks – Free

ACF setup:

  1. Create a new field group called “Category Bottom” (can be anything really)
  2. Create a field within the group. Can be called whatever you want, but I’d go with something that makes sense like “Category bottom text”.
  3. Set field type to be “Wysiwyg Editor”
  4. Set the Location rules to be for Taxonomy equals to Category
  5. Publish the field group

Genesis Simple Hooks setup:

  1. Paste this code into the ‘genesis_after_endwhile’ box:
<?php

$term = get_queried_object();
$bottom_text = get_field('category_bottom_text', $term);

if ($bottom_text ) {
   echo $bottom_text;
}

?>
  1. Check the box for “Execute PHP on this hook?”

Now all you have to do is go to your Category Editor, scroll to the bottom, and your box will be there. Add text to this box, and it will display after the post loop at the bottom of the category page. The only issue with this is that the Pagination is using the same hook, and has priority, so it shows up above our new text box.

The Genesis Simple Hooks plugin doesn’t have a way to indicate a higher priority for your code. To get around this, we’ll have to add the hook code directly in the child theme’s function.php file.If you’re familiar with using FTP or SFTP to edit code on your server, awesome. That is the safest way to do it, and protect from major errors.

Since WordPress 4.9, it is relatively safe to edit the functions file directly in your dashboard. You can do this by going to Appearance > Theme Editor > functions.php. Whichever way you are accessing the functions.php file, this is what you’ll want to add:

 // Tying our code to the genesis hook. Setting priority to 5 puts our code above the Pagination

add_action('genesis_after_endwhile', 'bth_after_category_text', 5);

// Our Function
function bth_after_category_text() {
   $term = get_queried_object();

// Field name should match what you created in Advanced Custom Fields

$bottom_text = get_field('category_bottom_text', $term);

   if ($bottom_text ) {
      echo $bottom_text ;
   }
}

And that’s it. This will add your text on the bottom of the category pages, and it will show up above the pagination section. If you have any issues or questions at all, let me know!

By Ben

I started working with WordPress in 2012. Building hundreds of custom websites over the years has brought all kinds of puzzles to solve. This has taught me a lot, and I am always amazed how much more there is to learn.