I spent all morning researching and, with the help of SO, figured out how to grab the innerHTML of elements using Javascript.
This is to populate meta tags for search and social open graph. The tag in question here is the meta description tag.
What I used in Javascript was this:
document.getElementsByClassName("report-description-text")[0].childNodes[2].nodeValue;
The (somewhat awkward) html structure is this:
<!-- start report description -->
<div class="report-description-text">
<h5>Description</h5>
Welcome to Ushahidi. Please replace this report with a valid incident
<br/>
</div>
I want to grab the text "Welcome to Ushahidi...". But this text is not inside any html tags, it's just text. The above JS works in grabbing that text.
I then tried to integrate this into a PHP script but was swiftly downvoted since, I now know, that you cannot execute JS on the server side (I knew that but never had enough practice to really get it).
The PHP script looks like this:
if( strpos($url, '/reports/view') === 0 ) {
echo '<!-- Make this site discoverable, shareable and searchable -->
<meta name="description" content=[figure out what to put here]/>
// deal with these other metas later
<meta name="author" content="my name" />
I'd like the content of the content to be, in this example: content="Welcome to Ushahidi...." />
How would I do that using PHP? Is it as straightforward as with JS? I did some research but just worked myself into confusion.