There are many good solutions for doing this, you should follow the link that cjbj has provided in the comments.
I am suggesting to use PHP's debug_backtrace()
function:
function wpse_228223_verify_caller_file( $file_name, $files = array(), $dir = '' ) {
if( empty( $files ) ) {
$files = debug_backtrace();
}
if( ! $dir ) {
$dir = get_stylesheet_directory() . '/';
}
$dir = str_replace( "/", "\\", $dir );
$caller_theme_file = array();
foreach( $files as $file ) {
if( false !== mb_strpos($file['file'], $dir) ) {
$caller_theme_file[] = $file['file'];
}
}
if( $file_name ) {
return in_array( $dir . $file_name, $caller_theme_file );
}
return;
}
Usage:
In your content-form
template, pass the file name in the first param:
echo var_dump( wpse_228223_verify_caller_file( 'header.php' ) ); // called from header
echo var_dump( wpse_228223_verify_caller_file( 'footer.php' ) ); // called from footer
and there in your template you can add the appropriate class names..
Please give it few tests first. The way I tested it it worked fine. Since you are creating your own custom template which won't be called by default unless your call it, it should work fine.
get_template_part
" question. Lookee here: wordpress.stackexchange.com/questions/176804/…