In WordPress, is it possible to hide a HTML element by class or ID with php?
I've used css rule display: none;
but this is easily worked around...
I have tried the following via functions.php
but to no avail:
function MyTestFunction() {
obj = document.getElementById("div-or-class-id");
obj.style.visibility = "hidden";
console.log(obj.id);
console.log(obj);
}
}
Basically I need to hide a HTML element for good without anyone being able to alter the code via browser inspector. I'd like to prevent having to create a child theme and mess with templates too.
display:none
orvisibility:hidden
you just removed the element? This obviously isn't a practical suggestion if for any reason the page needs that element present to perform any function, but if it's just something visual that you want to hide permanently so no one can see it, then just remove it using JS.javascript
to remove the whole thing from your html. Or you could use cssdisplay: none;
to remove your element from the page. FYI, the snippet you provided us with is NOT php, so it won't work in thefunctions.php
file. I'm actually surprised that you didn't get any error running it!!!