Add “title” attribute to links

For SEO purposes, many researches state that title attribute might not be given much weight in ranking.
For user’s experience, the title attribute can provide descriptive text (or supplementary information) to the link.

To add title attribute to links in grid or list of Content Views, please add this code to file functions.php in the theme’s folder (or install this plugin Code Snippets then add this code to the “Code” textarea):

// Content Views Pro - add Title attribute to images
add_filter( 'wp_get_attachment_image_attributes', 'cv_add_tilte_for_image', 100, 3 );
function cv_add_tilte_for_image( $attr, $attachment, $size ) {
	global $cvp_process_settings;
	if ( $cvp_process_settings ) {
		global $post;
		// Get title of featured image first, then get the title of post
		$title			 = isset( $attachment->post_title ) ? $attachment->post_title : (isset( $post->post_title ) ? $post->post_title : '');
		$attr[ 'title' ] = esc_attr( $title );
	}
	return $attr;
}

// Content Views Pro - add Title attribute to links
add_filter( 'pt_cv_field_href_attrs', 'cvp_theme_add_title_to_links', 100, 3 );
function cvp_theme_add_title_to_links( $custom_attr, $open_in, $oargs = array() ) {
	global $post;
	if ( isset( $post->post_title ) ) {
		$custom_attr[] = 'title="' . esc_attr( $post->post_title ) . '"';
	}
	return $custom_attr;
}

Best regards,

Scroll to Top