Ciprian
Ciprian

Reputation: 31

Where is the <head> code located in wordpress?

I've been struggling with this thing for days. I have a custom theme on my WP site (including frameworks and fancy plugins). In my Chrome dev console I get an error because the index page tries to load a file from a host that doesn't exist. I located that code in the section of the generated HTML, however I can't find the php file that generates the so that I can remove the line. I hope that my question is clear enough. I'm a total beginner in coding.

Thanks.

Upvotes: 3

Views: 19431

Answers (3)

user7489118
user7489118

Reputation:

Usually such text is situated in header.php, but not always. I can recommend to download your site by any FTP manager, then open the folder in Total Commander, and search the necessary text among the whole site.

Upvotes: 2

ppajer
ppajer

Reputation: 3145

While @Johannes is right about checking the header.php file in your theme, it's worth noting a few additional things.

Check the URL of the missing file

Most of the time plugins and themes only reference their own files (or rarely files from CDNs). If the missing file should be hosted on your domain, the segment after http://yourdomain.tld/wp-content/ should give you a clue as to which theme or plugin tries to load that file.

There are multiple ways to add resources in WP

Once you track down the theme or plugin responsible for including your missing file, you should check their code for the following:

  • header.php and footer.php if it is a theme. Most of the time resources are included in script or link tags here.
  • calls to wp_enqueue_script() and wp_enqueue_style(). These might be located anywhere, not only inside template files.
  • if you can, run a search for the filename (and the filename only, because the full URL is possibly built using something like get_template_directory_uri()) against the entire installation

This should lead you to the culprit. Also, once you track down the theme or plugin causing the error, you should diff it with a freshly downloaded copy to see if you can replace the missing files, in case they went missing during upload.

Upvotes: 3

Johannes
Johannes

Reputation: 67776

Usually it's in the header.php file of the theme that you use (in that theme's folder which is inside the "wp-content/themes" folder)

Just in case your theme is a "child-theme" (derived from and dependent on another theme): If there's no header.php file in the child-theme folder, WP uses the header.php of the parent theme.

ADDITION: It's also possible that code is inserted into the head section by plugins (extending the regular WP functionality). In that case you won't find it in the header.php file. You can try to deactivate plugins one by one to find out which plugin is responsible. Sometimes you can also tell by the name of classes or attributes of the code in question.

Upvotes: 4

Related Questions