%CODE1% – Where is it!?
-
Hello All,
I created the website for our campaign several years ago, it was my first attempt and managed it with the help of this forum and Googling.
On the Maps page it had an interactive map, whereby one could enter the name of a town and it was shown on the map.
This was made possible with the help of %CODE1% – the problem now is that for some reason the map is now a grey block and doesn’t seem to work.
The source of the map is an external page https://wikishire.co.uk/map/ which works fine.
I can’t find where the settings relating to %CODE1% are in my WordPress Dashboard, so that I can check it for possible issues causing it not to work properly.
It’s a long time since I configured it and I can’t remember how I did it!
If anyone could please help I would really appreciate it.
Andrew.The page I need help with: [log in to see the link]
-
It is a grey block because
OpenLayers is not definedYou can see this in the JavaScript console when you call up the website.
My guess is that a plugin you have been using here is no longer available or at least no longer active. Unfortunately, you cannot recognise which one it is or was. The placeholder
%CODE1%is also far too general. Have a look in the list of your plugins to see if one is deactivated, which it could be.If %CODE1% is a plugin, you can check its code in the wp-content/plugins folder in the root and figure out what is the link to its configuration page. If you are not familiar with the PHP code, you can share the link to its code so that i could help you out.
Thank you both for your replies. All the plugins and widgets are active and updated.
After regression therapy I managed to find Custom Fields relating to the Wikishire Map page on my site, I had to enable the show custom fields toggle, deep in the settings.
CODE1 has this value:<style> #map { position: relative; width: 100%; height: 600px; background-color: gray; z-index: 0; } div#input { position: absolute; left: 4em; top: 1em; z-index: 1; background-color: #ccc; border: 1px solid #888; vertical-align: center; border-radius: 4px; } div#input input { font-size: 12pt; } input[type=text] { width: 14em; margin-left: 4px; margin-top: 2px; margin-bottom: 2px; padding: 2px; } div#results { visibility: hidden; position: absolute; opacity: 0.9; top: 5em; left: 5em; width: 30em; z-index: 2; background-color: #eee; text-color: #444; font-family: sans-serif; font-size: 10pt; padding: 1em; overflow: auto; } div#prev, div#next { float: right; } img.closebutton { float: right; width: 17px; right: 17px; } </style> <script src="https://wikishire.co.uk/map/inset"></script> <div id="input"> <form action="javascript:void(0);" onsubmit="check(); return false;"> <input type="text" id="q" size="26" placeholder="Place, county or postcode" /> <input type="submit" value="OK" /> </form> </div> <div id="map"></div> <div id="results"> </div> <script type="text/javascript"> if (window.addEventListener) window.addEventListener("load", search_init, false); else if (window.attachEvent) window.attachEvent("onload", search_init); var WGS84 = new OpenLayers.Projection("EPSG:4326"); var mercator = new OpenLayers.Projection("EPSG:900913"); var popup_visible = results_visible = check_waiting = false; var gazsearch = ""; function search_init() { markers = new OpenLayers.Layer.Markers("markers"); map_map.addLayer(markers); querybox = document.getElementById("q"); results = document.getElementById("results"); } // Check contents of query box function check() { if (check_waiting) return; if (popup_visible) close_cloud(); if (results_visible) close_results(); if (querybox.value == "") return; check_waiting = true; var r = new XMLHttpRequest(); query = querybox.value; if (ispostcode(query)) { // Dealing with postcode input pc = query.replace(/ /g, "").toUpperCase(); if (pc.length >= 5 && pc.length <= 7) { oc = pc.substring(0, pc.length-3); ic = pc.substring(pc.length-3); querybox.value = query = oc+" "+ic; } else { // Just a postcode district oc = pc; ic = ""; querybox.value = query = pc; } // Are we looking at a detached layer? if (map_type.indexOf("detached") == -1) r.open("GET", "https://wikishire.co.uk/map/lookup?q="+oc+ic, true); else r.open("GET", "https://wikishire.co.uk/map/lookup?q="+oc+ic+"&hcs=B", true); r.onreadystatechange = function() { process_point(r, query); } r.send(null); } else if (iscoords(query)) { // Dealing with comma-separated co-ordinates querybox.disabled = "disabled"; coords = query.replace(/ /g, ""); var c = coords.split(","); var loc = new OpenLayers.LonLat(c[1], c[0]).transform(WGS84, mercator); map_map.moveTo(loc, 7); query = querybox.value = coords; // Are we looking at a detached layer? if (map_type.indexOf("detached") == -1) r.open("GET", "https://wikishire.co.uk/map/lookup?q="+coords, true); else r.open("GET", "https://wikishire.co.uk/map/lookup?q="+coords+"&hcs=B", true); r.onreadystatechange = function() { process_point(r, coords); } r.send(null); } else if (iscounty(query)) { // Dealing with direct county name input county = query.replace(/^ */g, ""); r.open("GET", "https://wikishire.co.uk/map/data?q="+county, true); r.onreadystatechange = function() { process_data(r); } r.send(null); } else { // Everything else is a Gazetteer search if (query == gazsearch) { results.style.visibility = "visible"; results.style.opacity = "0.9;"; results_visible = true; check_waiting = false; querybox.blur(); } else { gazsearch = query; r.open("GET", "https://wikishire.co.uk/map/gazetteer?q="+gazsearch, true); r.onreadystatechange = function() { process_gaz(r); } r.send(null); } } } // Handle CSV point result from postcode or co-ord lookup function process_point(r, label) { if (r.readyState != 4) return; querybox.disabled = ""; if ((r.status != 200) || (r.responseText == "invalid\n")) { check_waiting = false; return; } check_waiting = false; var c = r.responseText.split(";"); var county = c[0]; var loc = new OpenLayers.LonLat(c[2], c[1]).transform(WGS84, mercator); map_map.setCenter(loc); open_cloud(loc, label+"<br /><b>"+county+"</b>"); querybox.value = label; } // Process CSV data from county lookup function process_data(r) { if (r.readyState != 4) return; if ((r.status != 200) || (r.responseText == "invalid\n")) { check_waiting = false; return; } var data = r.responseText.split(";"); var county = data[0]; var area = parseInt(data[1]).toLocaleString(); var area_det = parseInt(data[2]).toLocaleString(); var pop = parseInt(data[3]).toLocaleString(); var centre = data[4].split(","); var zoom = data[5].split(","); var zoombounds = new OpenLayers.Bounds(zoom).transform(WGS84, mercator); var loc = new OpenLayers.LonLat(centre).transform(WGS84, mercator); // If we are looking at a detached layer, then show detached area if (map_type.indexOf("detached") != -1) area = area_det; var data = "<b><a href=\"https://wikishire.co.uk/wiki/"+county+"\">"+county+"</a></b><br />Area: "+area+" sq mi."; if (pop != 0) data += "<br />Population: "+pop; map_map.zoomToExtent(zoombounds); open_cloud(loc, data); querybox.value = county; check_waiting = false; } // Process JSON resuls from Gazetteer lookup function process_gaz(r) { if (r.readyState != 4) return; if (r.status != 200) return; data = JSON.parse(r.responseText); if (data.head.totalResults == 0) { check_waiting = false; results.innerHTML = "<div style=\"float: left\"><b>No results</b> for <i>'"+data.head.searchTerms+"'</i></div><img class=\"closebutton\" src=\"https://wikishire.co.uk/map/img/close.gif\" onclick=\"close_results()\">\n"; results.style.visibility = "visible"; results.style.opacity = "0.9"; results_visible = true; return; } querybox.value = data.head.searchTerms; if (data.head.totalResults > 1) { check_waiting = false; querybox.blur(); var start = data.head.startIndex; var total = data.head.totalResults; var page = total-start > 10 ? 10 : total-start; var html = "<div style=\"float: left\"><b>Results "+(start+1)+"–"; html += (start+page)+" of "+total+"</b></div><img class=\"closebutton\" src=\"https://wikishire.co.uk/map/img/close.gif\" onclick=\"close_results()\">\n"; if (start+page < total) html += "<div id=\"next\"><button type=\"button\" onclick=\"next("+(start+10)+")\">Next</button></div>\n"; if (start > 0) html += "<div id=\"prev\"><button type=\"button\" onclick=\"next("+(start-10)+")\">Previous</button></div>\n"; html += "<table style=\"clear: both\">\n<tr><th>Place</th><th>County</th><th>Co-ords</th>\n"; for(var i = 0; i < page; i++) { var label = data.results[i].label; var type = data.results[i].type; var county = data.results[i].county; var easting = data.results[i].easting; var northing = data.results[i].northing; var lat = data.results[i].latitude; var lon = data.results[i].longitude; html += "<tr><td><a href=\"javascript:void(0)\" onclick=\"pin('"+escape(label)+"','"+type+"','"+county+"',"+lat+","+lon+")\" title=\""+get_type(type)+"\">"+label+"</a></td><td>"+county+"<td>"+lat+","+lon+"</td></tr>\n"; } results.innerHTML = html+"</table>\n"; results.style.visibility = "visible"; querybox.blur(); results_visible = true; return; } if (data.head.totalResults == 1) { querybox.value = data.results[0].label; pin(data.results[0].label, data.results[0].type, data.results[0].county, data.results[0].latitude, data.results[0].longitude); } } // Request a new block of Gazetteer results function next(offset) { var r = new XMLHttpRequest(); var url = "https://wikishire.co.uk/map/gazetteer?q="+gazsearch; if (offset != 0) url += "&o="+offset; r.open("GET", url, true); r.onreadystatechange = function() { process_gaz(r); } r.send(null); } // Place a pin from a gazetteer search result function pin(label, type, county, lat, lon) { var loc = new OpenLayers.LonLat(lon, lat).transform(WGS84, mercator); close_results(); map_map.setCenter(loc); var html = unescape(label); var type = get_type(type); if (type != "place") html += " <small>("+type+")</small>"; if (county != "None") html += "<br /><b>"+county+"</b>"; open_cloud(loc, html); check_waiting = false; } // Convert Gazetteer result code into text function get_type(type) { switch(type) { case 'C': type = "City"; break; case 'T': type = "Town"; break; case 'O': type = "village"; break; case 'W': type = "water"; break; case 'H': type = "hill"; break; case 'R': type = "roman antiquity"; break; case 'F': type = "wood"; break; case 'FM': type = "farm"; break; case 'NT': type = "National Trust"; break; default: type = "place"; } return type; } // Open a pop-up cloud function open_cloud(loc, text) { point = new OpenLayers.Marker(loc); cloud = new OpenLayers.Popup.FramedCloud("cloud", loc, null, text, null, true, close_cloud); markers.addMarker(point); map_map.addPopup(cloud); popup_visible = true; } // Close the cloud function close_cloud() { markers.removeMarker(point); map_map.removePopup(cloud); point.destroy(); cloud.destroy(); popup_visible = false; } // Close results box function close_results() { results.style.opacity = "0;"; results.style.visibility = "hidden"; results_visible = false; } // Query is a postcode or alphanumeric grid reference function ispostcode(q) { if (q.search(/[A-Z]+ *[0-9]+/i) != -1) return true; return false; } function iscoords(q) { if (q.search(/[^0-9\.\-,]/)) return true; return false; } function iscounty(q) { c = q.replace(/^ */g, "").toLowerCase().replace(/ +/g, " ").replace(".", ""); c = c.replace("county of ", ""); switch(c) { case "aberdeenshire": case "anglesey": case "angus": case "forfarshire": case "forfars": case "county antrim": case "argyllshire": case "argyll": case "county armagh": case "ayrshire": case "banffshire": case "bedfordshire": case "berkshire": case "berks": case "berwickshire": case "berwicks": case "breconshire": case "brecknockshire": case "brecons": case "buckinghamshire": case "bucks": case "buteshire": case "bute": case "caernarfonshire": case "caernarfons": case "caithness": case "cambridgeshire": case "cambs": case "cardiganshire": case "cards": case "carmarthenshire": case "carms": case "cheshire": case "ches": case "clackmannanshire": case "clacks": case "cornwall": case "cromartyshire": case "cumberland": case "denbighshire": case "denbighs": case "derbyshire": case "derbys": case "devon": case "devonshire": case "dorset": case "dorsetshire": case "downshire": case "county down": case "down": case "dumfriesshire": case "dunbartonshire": case "dunbartons": case "county durham": case "east lothian": case "haddingtonshire": case "haddingtons": case "essex": case "fermanagh": case "county fermanagh": case "fife": case "fifeshire": case "flintshire": case "flints": case "glamorgan": case "glamorganshire": case "glam": case "gloucestershire": case "glos": case "hampshire": case "hants": case "herefordshire": case "herefords": case "hertfordshire": case "herts": case "huntingdonshire": case "hunts": case "invernesshire": case "invernessshire": case "inverness-shire": case "kent": case "kincardineshire": case "kincardines": case "king's county": case "kinrosshire": case "kinrossshire": case "kinross-shire": case "kirkcudbrightshire": case "lanarkshire": case "lanarks": case "lancashire": case "lancs": case "leicestershire": case "leics": case "lincolnshire": case "lincs": case "county derry": case "county londonderry": case "merionethshire": case "merioneth": case "middlesex": case "midlothian": case "edingurghshire": case "edingurghs": case "monmouthshire": case "mon": case "montgomeryshire": case "monts": case "morayshire": case "moray": case "elginshire": case "nairnshire": case "norfolk": case "northamptonshire": case "northants": case "northumberland": case "nottinghamshire": case "notts": case "orkney": case "oxfordshire": case "oxon": case "peeblesshire": case "pembrokeshire": case "pembs": case "perthshire": case "perths": case "queen's county": case "radnorshire": case "radnors": case "renfrewshire": case "renfrews": case "rosshire": case "rossshire": case "ross-shire": case "roxburghshire": case "roxburghs": case "rutland": case "selkirkshire": case "selkirks": case "shetland": case "shropshire": case "salop": case "somerset": case "somersetshire": case "som": case "staffordshire": case "staffs": case "stirlingshire": case "stirlings": case "suffolk": case "surrey": case "sussex": case "sutherland": case "tyrone": case "warwickshire": case "warks": case "west lothian": case "linlithgowshire": case "linlithgows": case "westmorland": case "wigtownshire": case "wigtowns": case "wiltshire": case "wilts": case "worcestershire": case "worcs": case "yorkshire": case "yorks": case "yorkshire, east riding": case "yorkshire, north riding": case "yorkshire, west riding": case "east riding of yorkshire": case "north riding of yorkshire": case "west riding of yorkshire": case "east riding": case "north riding": case "west riding": case "lindsey": case "kesteven": case "parts of lindsey": case "parts of kesteven": case "parts of holland": case "lincolnshire, parts of lindsey": case "lincolnshire, parts of kesteven": case "lincolnshire, parts of holland": case "county carlow": case "county cavan": case "county county clare": case "county cork": case "county donegal": case "county dublin": case "county galway": case "county kerry": case "county kildare": case "county kilkenny": case "county laois": case "county leitrim": case "county limerick": case "county longford": case "county louth": case "county mayo": case "county meath": case "meath": case "county monaghan": case "county offaly": case "county roscommon": case "county sligo": case "county tipperary": case "county waterford": case "county westmeath": case "westmeath": case "county wexford": case "county wicklow ": return true; default: return false; } } </script>As I previously mentioned, I managed to create my page to show the interactive map by pointing it to https://wikishire.co.uk/map – I obtained the script (if that’s the right word) by clicking on Inspect and using the information there, somehow it worked, but recently something changed and so my page just shows the grey box.
I looked again at the Source of https://wikishire.co.uk/map but I can’t find anything that exactly matches the Value I previously added in Custom Field.
I am completely out of my depth it seems. If you could possibly help me work out what’s gone wrong, and what can be done to get this working again I would be eternally grateful.
Thank you for any help offered.
Andrew.The problem is not caused by the script itself but by its position in the source code and the way it is integrated into the website. The JavasScript error when loading is
OpenLayers is not definedThis is because some component in your project that provides OpenLayers is no longer present. Either a 2nd code is missing in the output or you have used a plugin for it, which is no longer there.
Thanks for your reply. This was originally implemented by using a plugin “Code Embed” by David Artiss.
π§© Code Embed provides a very easy and efficient way to embed code (JavaScript and HTML) in your posts and pages.
This is the description, and it’s the only plugin listed with that jigsaw icon thing, so I am not sure if it’s just part of the description, or it means something.
It’s in the settings of this plugin where %CODE1% is specified with the Value.
If this is plugin is perhaps the source of the problem, could you please recommend another plugin I could install and try instead of this one?I tried this, deactivate, delete, then re-install that same Code Embed plugin.
Also, changed %CODE1% to {{CODE1}} in case that made any difference, but without success, still the grey box instead of the interactive map on my page https://britishcounties.org/wikishire-map/
The script set in Value seems very long and I am wondering if it’s needed and if it’s actually correct, maybe something changed on the source website?
Sorry to be a thicko and be completely out of my depth (I am under pressure from the members of the campaign to try and fix this), using the Code Embed plugin, what Value should %CODE1% be in order to achieve this interactive map but on our campaign page please? https://wikishire.co.uk/map
Originally I looked at the page source and simply copied that to the Value field, and I was amazed it actually worked, but I have no idea what might have changed to cause it to stop working on our page, but the source website is working fine.
Thanks for any help or advice.
Andrew.The Code Embed plugin is only used to integrate your own code into the page. If the code you put there does not contain everything that is necessary, the code will not run. However, the plugin can’t do anything about that because it only gives you the option to integrate it. It doesn’t think for you.
So if you didn’t use another plugin to help, the error must be in the code you are using. I just discovered that your code also loads a JavaScript file from the other website: https://wikishire.co.uk/map/ol.js – so you are dependent on this website where you copy the code from have. My guess is that this source file has changed. This means your older code can no longer run with this file as a base, which leads to the error.
You have 3 options:
a) You try to copy the current status of the scripts from the other side. However, it is unlikely that this will work successfully, as today’s scripts for outputting maps (regardless of the basis) are designed to be executed in a single website – not to be copied anywhere. You can contact the operator of this website for support.
b) You create your own maps. There are many plugins for WordPress that make this possible, even if the design is usually very difficult. Check out the options here: https://wordpress.org/plugins/tags/openstreetmap/
c) You hire someone to set it up for you. You can find someone like that here: https://jobs.wordpress.net/You have a version mismatch with the version of OpenLayers you are trying to use and the version that is used in https://wikishire.co.uk/map/inset
The JavaScript code used on https://wikishire.co.uk/map/ is Version 6 or above, so looking at the source of your page it seems you need to copy the code from https://wikishire.co.uk/map/slippy.js to replace what you currently have as it uses ‘ol’ rather than ‘OpenLayers’.
The topic ‘%CODE1% – Where is it!?’ is closed to new replies.