I’m not sure how to embed Javascript into a WordPress Page

So I have a prayer times script that I want to embed into a wordpress page.
Here is the link to it: http://praytimes.org/manual/

There is basically a PrayTimes.js file that I have attempted to include into the header.php/page.php file without success.

Read More

the code that I would post in a regular HTML page would look like this:

<!DOCTYPE html>
<html>
<head>
    <title> Daily Prayer Timetable </title>
    <style>
        body, td, th {font-family: verdana; font-size: 12px; color: #404040;}
        #timetable {border-width: 1px; border-style: outset; border-collapse: collapse; border-color: gray; width: 9em;}
        #timetable td, #timetable th {border-width: 1px; border-spacing: 1px; padding: 2px 4px; border-style: inset; border-color: #CCCCCC;}
        #timetable th {color:black; text-align: center; font-weight: bold; background-color: #F8F7F4;}
    </style>
</head>

<body>

<script type="text/javascript" src="../PrayTimes.js"></script>

<br>
<p align="center">Waterloo, ON, Canada<p>
<div align="center" id="table"></div>

<script type="text/javascript">

    var date = new Date(); // today
    var times = prayTimes.getTimes(date, [43, -80], -5);
    var list = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'];

    var html = '<table id="timetable">';
    html += '<tr><th colspan="2">'+ date.toLocaleDateString()+ '</th></tr>';
    for(var i in list)  {
        html += '<tr><td>'+ list[i]+ '</td>';
        html += '<td>'+ times[list[i].toLowerCase()]+ '</td></tr>';
    }
    html += '</table>';
    document.getElementById('table').innerHTML = html;

</script>

</body>
</html>

I’m just not sure how to embed this into a WordPress page. I only need to use it once.

Related posts

Leave a Reply

2 comments

  1. You should put scripts between head tags.

    <!DOCTYPE html>
    <html>
    <head>
        <title> Daily Prayer Timetable </title>
        <style>
            body, td, th {font-family: verdana; font-size: 12px; color: #404040;}
            #timetable {border-width: 1px; border-style: outset; border-collapse: collapse; border-color: gray; width: 9em;}
            #timetable td, #timetable th {border-width: 1px; border-spacing: 1px; padding: 2px 4px; border-style: inset; border-color: #CCCCCC;}
            #timetable th {color:black; text-align: center; font-weight: bold; background-color: #F8F7F4;}
        </style>
        <script type="text/javascript" src="../PrayTimes.js"></script>
    </head>
    
    <body>
    
    <br>
    <p align="center">Waterloo, ON, Canada<p>
    <div align="center" id="table"></div>
    
    <script type="text/javascript">
    
        var date = new Date(); // today
        var times = prayTimes.getTimes(date, [43, -80], -5);
        var list = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'];
    
        var html = '<table id="timetable">';
        html += '<tr><th colspan="2">'+ date.toLocaleDateString()+ '</th></tr>';
        for(var i in list)  {
            html += '<tr><td>'+ list[i]+ '</td>';
            html += '<td>'+ times[list[i].toLowerCase()]+ '</td></tr>';
        }
        html += '</table>';
        document.getElementById('table').innerHTML = html;
    
    </script>
    
    </body>
    </html>