tripl3inf
7/5/2015 - 5:48 AM

Filter "the_content" Conditionally based on post/page name

Filter "the_content" Conditionally based on post/page name

/**
 * conditionally serve template parts based on previously created page name
 *
 * @param $content
 * @return mixed
 */
function my_the_content_filter($content) {
	// created page/post name programatically before
	if ($GLOBALS['post']->post_name == 'coupon-creator') {
		get_template_part('templates/ccdash/ccdash-coupon-creator');
	}
	// otherwise returns the database content
	return $content;
}

add_filter( 'the_content', 'my_the_content_filter' );