get_template_part not working - WordPress

Viewed 2430

i'm using get_template_part('theme-templates/opt_header1') function in header.php and again using get_template_part('carousal') function in opt_header1.php. however, get_template_part('theme-templates/opt_header1') function in header.php is working fine but i want to use another template part inside the opt_header1.php which is carousal.php but it is not working.

folder structure is like below...

[folder]

     [template-part]

     ... opt_header1.php

     ... carousal.php

     [/template-part]

..header.php

[/folder]

using...

get_template_part('carousal');

please help :)

1 Answers

You need to tell get_template_part() the path of the file to add with reference to the theme's root directory.

So you need to do this:

get_template_part('theme-templates/carousal');

Without telling get_template_part the relative path of the file (carousal.php), the function is looking (and failing) for carousal.php in :

  1. child-theme/carousal.php
  2. parent-theme/carousal.php
Related