Soliloquy Documentation

Documentation, Reference Materials, and Tutorials for Soliloquy

Featured Content Addon: Change Post Link

Important: This doc assumes you’re comfortable creating and/or editing PHP files in your WordPress installation and is intended for advanced users.

Note: This document is relevant only if you have a Developer or Master license and you’re using the Featured Content Addon.

You can change the link on each Featured Content slide following this guide.

Step 1 – Create Plugin File

The first step is to create a new php file in the wp-content/plugins/ directory of your WordPress installation. The easiest way to do this is using your favorite FTP program or through your web hosting account’s file editor (if they provide one).

Once you’ve navigated to the wp-content/plugins/ directory, create a new file with the name soliloquy-featured-content-change-post-link.php

Step 2 – Edit the New Plugin File

Next, you’ll want to copy and paste the following code into the soliloquy-featured-content-change-post-link.php plugin file you’ve created:

<?php
/**
* Plugin Name: Soliloquy - Featured Content - Change Post Link
* Plugin URI: https://soliloquywp.com
* Version: 1.0
* Author: Tim Carr
* Author URI: http://www.n7studios.co.uk
* Description: Change the Post's link on Featured Content Slides
*/

/**
* Change the Slide/Image link, if "Link Image to Post URL" is enabled
*
* @param array 		$item 	Slide
* @param array 		$fc 	WordPress Posts
* @param array 		$data 	Slider Config
* @param WP_Post 	$post 	WordPress Post
* @return array     		Slide
*/
function sol_soliloquy_fc_change_post_link_image( $item, $fc, $data, $post ) {

	// Define your link here
	// If using ACF, remember to change the below parameters to get the right field from the right Post
	// See: http://www.advancedcustomfields.com/resources/get_field/
	$link = get_field( 'featured_link', $post->ID );

	if ( ! empty( $item['link'] ) ) {
		$item['link'] = $link;
	}

	return $item;

}
add_filter( 'soliloquy_fc_image', 'sol_soliloquy_fc_change_post_link_image', 10, 4 );

/**
* Change the Title link
*
* @param string 	$content 		HTML Content
* @param WP_Post 	$post 			Featured Content Post
* @param array 		$data Soliloquy Slider Configuration Data
* @return string 					HTML
*/
function sol_soliloquy_fc_change_post_link_title( $content, $post, $data ) {

	// Define your link here
	// If using ACF, remember to change the below parameters to get the right field from the right Post
	// See: http://www.advancedcustomfields.com/resources/get_field/
	$link = get_field( 'featured_link', $post->ID );

	// Return amended link
	return '<h2 class="soliloquy-fc-title"><a class="soliloquy-fc-title-link" href="' . $link. '" title="' . esc_attr( $post->post_title ) . '">' . $post->post_title . '</a></h2>';

}
add_filter( 'soliloquy_fc_after_title', 'sol_soliloquy_fc_change_post_link_title', 10, 3 );

/**
* Change the "Continue Reading" link
*
* @param string $content HTML Anchor
* @param WP_Post $post Featured Content Post
* @param array $data Soliloquy Slider Configuration Data
* @return string HTML Anchor
*/
function sol_soliloquy_fc_change_post_link_read_more( $content, $post, $data ) {

	// Define your link here
	// If using ACF, remember to change the below parameters to get the right field from the right Post
	// See: http://www.advancedcustomfields.com/resources/get_field/
	$link = get_field( 'featured_link', $post->ID );

	// Return amended link
	return '<a href="' . $link . '" class="soliloquy-fc-read-more soliloquy-fc-content-above" title="' . __( 'Continue Reading', 'soliloquy-featured-content' ) . '">' . __( 'Continue Reading', 'soliloquy-featured-content' ) . '</a>';

}
add_filter( 'soliloquy_fc_read_more', 'sol_soliloquy_fc_change_post_link_read_more', 10, 3 );

Step 3 – Edit the Plugin File

This example code is not plug-and-play so you’ll need to be sure and edit the code to fit your specific needs. Change the $link variable to the link you want to use.

Step 4 – Activate the New Plugin

The last step is to navigate to the WordPress Admin > Plugins screen, locate the plugin named Soliloquy – Featured Content – Change Post Link and activate the plugin.

That’s it! You’ve successfully changed the link for each slide in your Featured Content sliders!

[i]
[i]