Envira Gallery Documentation

Documentation, Reference Materials and Tutorials for Envira Gallery

Adding Date, Author, Category, Taxonomy To Featured Content

If you are using the Featured Content addon and would like to add additional information to your output (such as author, date, category, or taxnomy information) you can do that through a filter provided in the plugin. This requires you to be a little familiar with WordPress coding but we can help walk you through how to do that!

This tutorial is a bit more technical than our other docs, but we’ll walk you through the process step by step. In order to get and potentially alter the standalone template settings, we’ll need to create and upload a basic WordPress plugin.

Creating the Plugin

We’ll begin by creating a custom plugin. Just add the following code to a new file at wp-content/plugins/envira-fc-add-content.php.

<?php
/**
* Plugin Name: Envira Gallery - Add Additional Content to Featured Content
* Plugin URI: https://enviragallery.com
* Version: 1.0
* Author: Envira Gallery Team
* Author URI: https://enviragallery.com
* Description: Adds Additional Content to Featured Content
*/

function envira_fc_date_terms( $content, $posts, $data, $post ) {

	// Start Config
	$slider_slugs = array(
		'add-filter-for-envira-fc-to-include-date-author-and-category-taxonomy-2876' //'your-slider-slug-name',
	);
    
	// Check slider ID is the one we want to amend
	if ( ! in_array( $data['config']['slug'], $slider_slugs ) ) {
		return $content;
	}

	$gallery = get_post( intval( $data['config']['id'] ) );
    
	// Build date and taxonomy terms content
	$additional_content =       
	 '<div class="envira-fc-author-name">'
		. __( 'Posted by: ', 'envira-featured-content-date-terms' ) . get_the_author() . '
	 </div>' .
	 '<div class="envira-fc-date">'
		. __( 'Published on ', 'envira-featured-content-date-terms' ) . get_the_date( 'dS F Y', $gallery->ID ) . ' 
	 </div>' .
	 '<div class="envira-fc-category"> '
		. __( 'in ', 'envira-featured-content-date-terms' ) . get_the_term_list( $gallery->ID, 'category', 'Categories: ', ', ' ) . '
	</div>';

	$content['caption'] = $content['caption'] . $additional_content;

	// Return content
	return $content;
	
}
add_filter( 'envira_featured_content_image', 'envira_fc_date_terms', 1, 4 );

If you’re unsure how to create a plugin file, follow these steps below:

  1. Open a text file and make sure that it is a plain text document. You can use a plain text editor like Notepad or a code editor of your choice.
  2. Next, copy and paste the code shown above into the file and save the file as envira-fc-add-content.php.
  3. Once you’ve saved the file you can easily upload this directly to your /plugins directory on your server using FTP or you can right-click on the text document and zip (or compress).
  4. Finally, log in to your WordPress dashboard and go to Plugins » Add New » Upload Plugin and upload the .zip file you just created in the previous step.

Activate the Plugin

Your final step is to activate the plugin you just uploaded. Simply navigate to the Plugins from within your WordPress dashboard and activate the Envira Gallery – Add Additional Content to Featured Content plugin.

And that’s it!