Home » Topics » Priority Support » Widget template in plugin directory

Widget template in plugin directory

ACF Widgets Support Priority Support Widget template in plugin directory

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #2375
    Tracey Kemp

    Hi Daron,

    Is it possible to have the template folder in a plugin?

    I’m using the following code in my plugin file and have a subfolder called ‘acf-widgets’. Here is my code:

    add_filter( 'acfw_custom_template_dir', 'my_acfw_custom_directory' );
    function my_acfw_custom_directory( $template_dir ){
      $template_dir = plugins_url( 'acf-widgets', __FILE__ );
      return $template_dir;

    What am I doing wrong?


    Tracey Kemp

    I’m using multisite if that makes a difference?

    Daron Spence

    Multisite shouldn’t make a difference.

    Have you tried dumping the variables to check what path is being returned? One thing that I think I can see a problem with, is you’re using the plugins_url() function which returns a URL (http://…etc). However, since we’re loading PHP files from the server, we want to return a path instead (srv/user/home/public_html/wp-content/…). You can’t execute code from a URL for obvious reasons 🙂

    Try out a different function (this one maybe? https://codex.wordpress.org/Function_Reference/plugin_dir_path) and see if that works. I may have written the documentation wrong so I’ll double check to make sure the example works.


    Tracey Kemp

    That did the trick! Thanks Daron.

    $template_dir = plugin_dir_path( __FILE__ ). 'acf-widgets';

    Daron Spence

    Awesome! Glad you got it figured out 🙂

    Looking back I do think I wrote the docs wrong so I’ll replace those sometime today.

    Have a great day Tracey 🙂

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Widget template in plugin directory’ is closed to new replies.