Skip to content

Instantly share code, notes, and snippets.

@danielpowney
Last active August 7, 2016 04:22
Show Gist options
  • Save danielpowney/87f211f8b11231fc192e6780f8a96b2f to your computer and use it in GitHub Desktop.
Save danielpowney/87f211f8b11231fc192e6780f8a96b2f to your computer and use it in GitHub Desktop.
<?php
/**
* Overrides templates with custom templates when needed
*
* @param unknown $templates
* @param unknown $slug
* @param unknown $name
* @return unknown
*/
function my_mrp_get_template_part( $templates, $slug, $name ) {
// get the post id
global $post;
$post_id = null;
if (isset( $post ) ) {
$post_id = $post->ID;
}
if ( $post_id == 7363 ) { // <<--- replace with your own post id or other condition
foreach ( $templates as $index => $template_slug ) {
if ( $template_slug == 'rating-form.php' ) {
$templates[$index] = 'amazon-rating-form.php';
} else if ( $template_slug == 'rating-item-results.php' ) {
$templates[$index] = 'amazon-rating-item-results.php';
} else if ( $template_slug == 'rating-entry-details-list.php' ) {
$templates[$index] = 'amazon-rating-entry-details-list.php';
}
}
}
return $templates;
}
add_action( 'mrp_get_template_part', 'my_mrp_get_template_part', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment