Add custom text, HTML before/after the Title, Thumbnail, Content, Meta Fields…

Content Views Pro helps you to show the Title, Thumbnail image, Content, Meta Fields, Custom Fields of any WordPress posts easily.
You might want to show dynamic, custom info before (or after) one of these fields. To do that, please add this code to file functions.php in the theme’s folder:

/**
 * Add extra info before/after the field.
 * @TODO: Remove any line below if you don't need
 */
add_filter( 'pt_cv_item_title', 'cvp_theme_custom_content_to_field', 10, 2 );
add_filter( 'pt_cv_item_thumbnail', 'cvp_theme_custom_content_to_field', 10, 2 );
add_filter( 'pt_cv_item_content', 'cvp_theme_custom_content_to_field', 10, 2 );
add_filter( 'pt_cv_item_meta-fields', 'cvp_theme_custom_content_to_field', 10, 2 );
add_filter( 'pt_cv_item_custom-fields', 'cvp_theme_custom_content_to_field', 10, 2 );

/**
 * The function to add extra content to before (or after) above field
 * @param string $html
 * @param object $post
 * @return string
 */
function cvp_theme_custom_content_to_field( $html, $post ) {

	$position = 'after'; // or 'before' the field

	ob_start();
	// @TODO: Add text, HTML, PHP code (access current post ID by $post->ID)

	$extra = ob_get_clean();
	if ( $position === 'after' ) {
		$html .= $extra;
	} else {
		$html = $extra . $html;
	}

	return $html;
}

Notice 1: This task requires your coding skills about PHP, HTML.

Notice 2: If you want to apply above code to specific view only, below this line:

function cvp_theme_custom_content_to_field( $html, $post ) {

please add this line:

global $pt_cv_id; if ( $pt_cv_id !== 'VIEW_ID' ) { return $html; }

and replace VIEW_ID with ID of your View.

Best regards,

Scroll to Top