Javasript in header

Hello!
This may be answered elsewhere, but I’m having a problem getting a javascript in the header of my wordpress site.
I’ve tried to use two plugins, but no joy.
Has this feature been buckled down for free hosting?
Or is this not possible with wordpress 6.0?

Thanks!

Welcome!

Please make sure you are selecting the correct template. I corrected it for you this time.

A one-second google search brings this back for the first result:

Is this what you are looking for?

7 Likes

Just as Greenreader9 stated

Please do your research before creating new topics! As your question might be answered already.

3 Likes

Thank you for the info. The reason I’ve asked here is because I know infinity free does puts limits on their free hosting to some degree. I’m trying to put a simple loan calculator on a test page. Here’s the link: https://codepen.io/tomhx/pen/XeVzoM
I suspect the theme I was using was limiting the insertion of any php into the header, no matter what plugin I was using, I’ve tried three. So I changed theme, and still won’t work, even though the code is there.
So…I’ve spent too much time on trying to get this to work. I’m going with another widget plugin. Another note, a lot of the calculator plugins don’t look right. Could be due to Wordpress 6.
Thanks again.

Like what kind of PHP are you trying to put there? Most of these plugins are for CSS/HTML only. If you want full control, I don’t think WordPress is going to work for you, it’s not meant for intense customization.

5 Likes

FYI: I don’t think you need to put anything in the page header for this to work. Javascript can be placed anywhere on the page. And the CSS is so simple that I would not bother using it if you’re going to integrate it into an existing page, and just leverage the styling options of the design of the page.

You can just take the table block from the example and dump that anywhere on the page where you want the stuff to be shown. And for the Javascript code you can just put script tags just above or below the form and put the Javascript in there.

As for the form looking weird: yes, that’s what you get when you try to integrate external code into an existing design. It can be fixed, but that requires some custom coding.

And please do aware that if you are going to integrate other code into a website, you will need some coding skill, or at least willingness to learn.

6 Likes

Well…I don’t know what’s wrong.
If I drop the html code and the javascript on a local html page on my workstation, open with a browser, it works.
Try to do the same on wordpress page, in the header or not, before or after the calculator html block, it just won’t work. (not bothering with css file.)
As I mentioned before, changed theme, same problem.

Could you please share the URL to the page on the WordPress where you’ve embedded the calculator? Maybe what we see there will tell us more about what you did, and provide pointers on how to make it work.

4 Likes

Sure, no problem.
Right now the javascript is after the calculator html
https://mortgage-calculators.net/test-calculator/

I checked the generated code but it looks like a LOT of HTML tags are mixed into the Javascript code, which why it’s no longer valid code.

I think you may need to tell WordPress that you’re giving it HTML code to use, and not text to be formatted. I’m not quite sure how this works, but I think this article explains how to do it.

6 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.