failed to use get_header in wordpress

0

I'm setting up a wordpress system to make development easier, and I created a theme and put it in the \ wp-content \ themes folder. The index.php, header.php, and footer.php files are in the \ wp-content \ themes \ Themacuria folder. I put in the root of WP a folder with the php files. When using the command get_header (); gave a fatal error. I think my problem is with the structure of WP.
How should I proceed?

    
asked by anonymous 07.06.2016 / 19:39

1 answer

1

get_header() is a WP method. Therefore, in order to be used, it must somehow be within the context of WP. From what I could understand from your question, you created the theme (i.e., index.php , header.php , and genre files), but you are trying to use the method in a file that is not within the theme. The fatal error is therefore natural.

WordPress works with Hierarchy_of_Modelos_WordPress"> Hierarchy of Templates , which allows you to create pages of various types in your following a certain logic. Trying to circumvent such logic (for example, trying to create pages in files outside the CMS framework) is generally not a good idea.

That said, I believe you have two options:

  • Use WP logic to create pages

    There are several internet tutorials on how to set up a theme for WP in the right way, such as this one . Try creating a template for a page, and within it invoke the get_header() method (in fact, try invoking it in index.php itself, activate your theme in the WP dashboard, see what happens). Here you can find good instructions on how to do this.

  • Embed the WP functions into your files.

    In particular, I do not like this solution, although I have already seen it being used extensively around, especially when it comes to integration with legacy applications. But in rare cases (which I do not believe is yours), it is the only option. This is to forcibly include the WP methods in .php files that are outside the logic of the same. For this, it is enough that you make a require , as follows,

    require('/caminho/para/o/arquivo/wp-blog-header.php');
    

    in the external file (which, in your case, I believe is what you are trying to access). This causes the file to have access to WP methods. You can read about this type of integration here .

  • As I said, the second solution does not please me, and I believe that from what I understand of your problem, it is more advantageous to use the WP architecture itself.

        
    08.06.2016 / 01:57