I’m currently working with WordPress. I have a hook that runs before a <title>
attribute is populated with text that a user enters in the dashboard.
Now I want to set a default title of each page to equal an <h1>
attribute text value on a current page. A fragment of the callback function for the hook I’m working with would look like:
if (!$seoTitle) {
$seoTitle = '<....>';
}
return $seoTitle;
I want seoTitle
to default to an <h1>
element text on the current page. Is it doable? How can I achieve this?
I’m not totally sure how you get your HTML but you could parse it with the built in DOM parser.
Assuming you have your HTML content within a variable and doing this after the page has fully loaded please take a look at the below example:
Should work. You can also break out of the php
?>
and then type regular html and then break in when you wanna echo the variable.