Jump to content

I'm planning to create a tool website using JavaScript


JK58

Recommended Posts

I'm planning to create a tool website using JavaScript, specifically a fireplace size calculator that I want to integrate into my existing WordPress site. Given that my website is built on WordPress, how can I effectively include the custom JavaScript code for the calculator? Are there any specific plugins or best practices I should follow to ensure smooth integration and functionality on my WordPress site?

My Code is Below:

HTML:
 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Fireplace Size Calculator</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="container">
        <h1>Fireplace Size Calculator</h1>
        <p>Calculate the ideal fireplace size for your living area.</p>
        <form id="calculator-form">
            <label for="width">Room Width (ft):</label>
            <input type="number" id="width" required>

            <label for="length">Room Length (ft):</label>
            <input type="number" id="length" required>

            <label for="height">Room Height (ft):</label>
            <input type="number" id="height" required>

            <button type="button" onclick="calculateSize()">Calculate</button>
        </form>
        <div id="result"></div>
    </div>

    <div class="footer">
        <p>Created by Fireplace Adviser</p>
    </div>

    <script src="script.js"></script>
</body>
</html>

CSS:
 

body {
    font-family: Arial, sans-serif;
    background-color: #f5f5f5;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}

.container {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    width: 300px;
    text-align: center;
}

h1 {
    margin-bottom: 20px;
    font-size: 24px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

input {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

button {
    background-color: #28a745;
    color: white;
    padding: 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    font-size: 16px;
}

button:hover {
    background-color: #218838;
}

#result {
    margin-top: 20px;
    font-size: 18px;
    font-weight: bold;
}

JavaScript:
 

function calculateSize() {
    const width = parseFloat(document.getElementById('width').value);
    const length = parseFloat(document.getElementById('length').value);
    const height = parseFloat(document.getElementById('height').value);

    if (isNaN(width) || isNaN(length) || isNaN(height)) {
        document.getElementById('result').innerText = "Please enter valid dimensions.";
        return;
    }

    const roomVolume = width * length * height;
    const btuRequired = roomVolume * 20; // Example formula: 20 BTUs per cubic foot
    const fireplaceSize = btuRequired / 1000; // Convert to approximate size in inches

    document.getElementById('result').innerText = 
        `Ideal Fireplace Size: ${fireplaceSize.toFixed(2)} inches`;
}

 

Link to comment
Share on other sites

  • 5 weeks later...

To integrate your custom JavaScript fireplace size calculator into a WordPress site, follow these steps:

  1. Use a Plugin for JavaScript Integration: One of the easiest ways is to use a plugin like "Insert Headers and Footers" or "WPCode" which allows you to add custom JavaScript directly to your pages or posts. Simply paste your JavaScript code in the footer section of the plugin settings. This ensures the script loads properly on all relevant pages.

  2. Embed HTML and CSS: For the HTML structure, use the Custom HTML Block or Shortcode block in your WordPress post/page editor. Insert your HTML and inline CSS, if needed, directly into the block.

  3. Upload CSS as an External File: If your CSS is in a separate file, you can add it by going to the WordPress Appearance > Theme File Editor, and enqueue it in the functions.php file. Alternatively, use a plugin to manage styles easily.

  4. Best Practices: Ensure that your JavaScript and styles do not conflict with existing WordPress themes or plugins by properly naming your functions and elements. Always test on staging environments before going live.

Interestingly, one of my competitors in Google SERP is also using a tool with similar functionality.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...