Code for adding text to every HTML file on website - javascript

So I have a website, https://coolkids.gq. I want to be able to add a certain line of code to every single HTML file on the website using another HTML, JavaScript or PHP file, but I am not sure how to do this.
How would I be able to write a script to add a line of custom code to every HTML page on my website?
Edit: As pointed out by charlieftl, I should clarify that all files are saved in either the /htdocs folder or in a folder inside of that.

yes you can, just make some folder named include or whatever and create for example loginForm.html sth like
<div>
<form>
....
</form>
</div>
and in pages where you want to put it use
<?php require('./include/loginForm.html') ?>; in place where you need it
Of course it need to be PHP page.
Good thing is to have also included header and footer in external html and include it on every php page ;D
if you want some js script in every page you need to add it manualy:
<script src="js/main.js"></script>
but it can be included in footer.

Related

Insert html pages into wordpress

I have an html site with a page of info for each county in the US. I want to convert this into a new wordpress site. I can do this one by one but my issue comes when I have mass changes to affiliate code or common text. I would have to got to each page and manually change it. but with over 3000 pages it would be way to time consuming. I dont want to use Iframes but would like to know if there is a way to call the html pages into the wordpress page that makes sense seo wise.
I am open to creating a page for each county or have one page with text or buttons on it with each county listed and when clicked will insert the info below. I know alot about static html coding but am new to php.
If you dont want Iframes, I think there only remain two options. I don't know if they will work in WordPress though.
1. PHP Include
With the very simple PHP include() statement, you can include the old html files in your new website. If you have a HTML-file for example, name your file yourname.php and add this in the position you want your old page to appear:
<?php include(path_to_old_page/name.html); ?>
This will include the full old page, but the file needs to be on the same server.
2. AJAX
With JavaScript you can perform XHTTP-requests to load files from the server. This is easiest when using jQuery. Here you can use the $(selector).load(path_to_old_page/name.html) statement. This will load the file in the HTML elements to which the selector applies.
(The selector works the same as CSS selectors, see the w3schools page for more)
This will also include the full old page, when it is on the same server
You can have your static pages in WordPress as well. Like if you want to create a new county named "example" you can create new WordPress page named "example" by entering title " example" .... now come to content. Just copy page content (only "example" county related html code from your static website) and place that code inside newly created WordPress "example" page. Make sure you add this html content inside 'text' tab in editor. Your page will be created with all your existing data ... now you can view this page and can use this page's URL where ever you want.

Where do I put the Google Analytics snippet when I'm including a header and footer?

So Google tells me to do this:
Paste your snippet (unaltered, in it’s entirety) into every web page you want to track. Paste it immediately before the closing </head> tag.
I understand this part, but as I'm including my header and footer, I guess this is not what I'm supposed to do.
If you use templates to dynamically generate pages for your site (like if you use PHP, ASP, or a similar technology), you can paste the tracking code snippet into its own file, then include it in your page header.
So I guess this is what I'm talking about(?), but I don't really get exactly where they want me to put the snippet. Do I put it in my header.php file once right before the closing </head> tag and then include the header.php file into every page or do I have to put the snippet directly in on every page? Incase I have to put the snippet in on every page, where exactly do I put it? Could someone please give me an example of this?
You can paste the Google Analytics Javascript snippet into its own file, call it ga.js for example.
Then in your header.php file, right before you close the tag, include that Javascript file, like so:
<script type="text/javascript" src="ga.js"></script>
This will load the GA code in your head section every time you load the header.php file. This should happen to every page that you load header.php automatically.
If you already have split your header, that I guess is included into you other html or php files, in it's own file and it includes the </head> tag, then you can put a script right above it.
This would look something like this:
[...]
<script>
<!-- Your personal google analytics snippet -->
</script>
</head>
Then all sites, that include your header.php, also load the snippet from analytics and get tracked.

Drop-down Redirect - Submit

i am using wordpress and i would like to create a drop down menu with select options and i found this thread which i think is exactly what i need Deactivate the 'Submit' button for the selected value in dropdown menu to be honest i don't know how to set up these elements html,js,css in order to achieve the result.I am a begginer and i would appreciate any kind of instructions.
Thank you for you time!
For instructions in HTML, CSS and JS go to the W3Schools website. I learned almost all that I know from there. If you need specific help THEN come asking here.
Let me assume that you are going to implement this in your WordPress themes index.php file. So, copy and paste the HTML code in to the html tag wherever you want to display the drop down box. Also copy and paste the javascript in to the script tag inside the head tag of the page. You can also paste the javascript code to a new file created inside the js folder inside the themes folder and call it from the head tag in index.php file. If you have any CSS you can either place it directly in the style tag inside head tag of index.php file or create a file in the css folder,copy the css code to it and call the CSS file from the head tag of index.php file.

add a specific set of javascript code to every single page

I have a fully functioning PHP system with various .php files handling different processes.
i need to add in a specific set of javascript code to every single page that's generated.
can any one tell me How to do this? is its possible thanks
Your "system" should include same header for all of the pages. And put your javascript to that file.
like:
header.php
<html>
<head>
<script>
// some script
</script>
</head>
<body>
index.php (main file)
<?php
include "header.php";
// Content
include "some_content.php";
include "footer.php";
?>
footer.php
<div><p>My footer</p></div>
</body>
</html>
Apart from the above methods, you can do this by another method.
Save the javascript as a separate file(code.js) and then using
<?php include("code.js"); ?>
in each of your files.
create a php footer and include this to every page. Place the markup for the script in the footer. The benefit of placing your javascript in the footer is that the page will render the page before trying to execute the script, making your page seem to load faster.
For each page add include "footer.php"
Create a master page which other pages will be included as child pages. In header of the master page the js files can be included and handled by checking you requested url
Example:
$requested_url = $_GET['requested_page'];
...
<script type="text/javascript" src="js_path/<?php echo "$requested_url.js" ?>" ></script>;
...

magento: add custom html on every page

I'd like to add some simple html code that makes use of javascript and .css, on every page of my website (magento).
I have figured out where to add the javascript and .css files in the head section.
Want to know where to put the html code? (possibly within the <body></body> tags, not in the <head></head>section)
Thanks
There is a configuration field in the backend for statistics, tracker, etc.
System > Configuration > Design > Footer

Categories