I'm trying to make a plugin that will change the behavior of a theme.

In the theme file I have a get_template_part('libs/templates/user_menu');.

I want to make my plugin "force" the get_template_part to return another slug file (a path to a file in the plugin's folder).

So far this is my code inside the plugin:

function wpse21352_template_part_cb( $slug )
    if(slug == 'user_menu') {
         return WP_PLUGIN_URL.'/'.$slug;
    } else {
         return $slug;

do_action( "get_template_part_user_menu", 'user_menu' );
add_action( 'wpse21352_template_part_cb', 'get_template_part_user_menu', 10, 1 );

1 Answer 1


Well, I handle this issue by adding some code above get_template_part() function in theme as:

/* If any filter set */


     $themePartSlug = apply_filters('ppr_one_search_item_view');
       $themePartSlug = 'templates/search/place';

in my plugin:

/* Plugin Code */
function get_template_part_place(){

    // Template file from plugin Directory 

add_filter( 'ppr_one_search_item_view', 'get_template_part_place');
/* plugin Code End*/

may this will help you

  • 1
    Please properly format your code. File an edit and use the WYSIWYG editor to format your code. Hint: use the {} sign just above the editor to add your code in a code block Dec 22, 2014 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.