// This is useful for dumb single page WordPress webapps which contain multiple Custom Post Types on a single page and need to link // i.e. smooth scroll to those sections on page load as you can't share URL's with hashes in them var pathnameMatch; var urlPathname = window.location.href; var sanitized = urlPathname .replace(/^http\:\/\//, '') // remove the leading http:// (temporarily) .replace(/\/+/g, '/') // replace consecutive slashes with a single slash .replace(/\/+$/, ''); // remove trailing slashes urlPathname = 'http://' + sanitized; if (urlPathname.includes("news")) { pathnameMatch = true; } if (pathnameMatch) { var beforeHashURL = urlPathname; var addHashURL = beforeHashURL.split("/").pop(); if (urlPathname.includes("#")) { var hashURLToAdd = addHashURL; window.location.replace('../' + hashURLToAdd); } else { var hashURLToAdd = "#" + addHashURL; window.location.replace('../' + hashURLToAdd); } }