Support » Developing with WordPress » function get_template_part() problem

  • Hello
    I created website in WordPress on local serwer
    I cut my website into several php files
    On subpages I put the same code as on the main page,only changing the content
    After clicking on the menu, the main page redirects me to the subpage and this error is displayed

    Fatal error: Uncaught Error: Call to undefined function get_template_part() in C:\xampp\htdocs\wordpress\wp-content\themes\web\contact.php:2 Stack trace: #0 {main} thrown in C:\xampp\htdocs\wordpress\wp-content\themes\web\contact.php on line 2

    please help

    Main page

    <?php defined('ABSPATH') || exit ;
     get_template_part('head');
     get_header();
     get_template_part('slider');
    get_template_part('content-index');
     get_footer();?>

    Subpage

    
    <?php 
     get_template_part('head');
     get_header();
     get_template_part('slider');
    get_template_part('content-contact');
     get_footer();?>
    
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    It sounds like the main page is directly requesting the sub-page’s template file without going through the usual WP permalink structure. For example a menu link might be <a href="contact.php">Contact</a>. Not only is requesting .php files incorrect in most cases, but relative references do not work well in WP. You should always use full permalink stye paths. For example <a href="http://localhost/wordpress/contact/>Contact</a>

    Even if your template files are responsible for all output, you still need a WP page created for every sub-page. You may specify a parent page for these sub-pages so that they stay bundled together in WP. Each page will need a title within WP, though it does not need to appear on the front end. No page content is necessary if content is embedded within the template.

    Each sub-page can have it’s own template file. If you correctly name each file, the template will be automatically used for that page. Once a sub-page’s main template file loads after making a proper permalink request, calls to get_template_part() will work as expected.

Viewing 1 replies (of 1 total)
  • The topic ‘function get_template_part() problem’ is closed to new replies.