failed to use get_header in wordpress

Asked

Viewed 317 times

0

I am mounting a system with wordpress to facilitate development and I created a theme and put in the folder wp-content themes.
The index.php, header.php and footer.php files are in the wp-content themes folder Themacuria.
I put a folder with php files in the WP root.
When using the get_header() command, fatal error occurred.
I believe my problem lies with the structure of WP.
How should I proceed?inserir a descrição da imagem aqui

1 answer

1


get_header() is a WP method. Therefore, to be used, it needs to 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 is trying to use the method in a file that is not within the theme. The fatal error is therefore natural.

Wordpress works with a Hierarchy of models, which allows you to create pages of various types in your application following a certain logic. Trying to circumvent such logic (for example, trying to create pages in files outside the CMS structure) is usually not a good idea.

That said, I believe you have two options:

  1. Use WP logic to create pages

    There are several tutorials on the internet of how to assemble a theme for WP in the correct way, such as this one. Try creating a template to a page, and within it invoke the method get_header() (in fact, try to invoke it on your own index.php, activate your theme on the WP panel, access the site and see what happens). Here you find good instructions on how to do this.

  2. Embed WP functions in your files.

    Particularly, I don’t like this solution, although I’ve seen it used extensively around, especially when it comes to integration with legacy applications. But in rare cases (which I don’t believe is yours), it’s the only option. It’s about forcibly including WP methods in files .php 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 gives the file access to WP methods. You can read about this type of integration here (in English).

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.