Archived topic
Move Post H1 + Create Variables
6 replies · Started by Jacob on February 17, 2022
Hi!
1) I wanted to know if its possible to move the H1 lower in our current theme? My kind of impression is the a "Genereate press element" is enabled and I'm not sure how to turn it off.
2) Within generate press variables, is it possible to create variables? for example h1 and body.
vid and post example in box thing.
Hi there,
1. You can find the Element in Appearance > Elements ( or via the Admin Bar > Elements Menu when viewing the page ) - the one you need to edit is title: Page header
When you edit that , you can a) remove the Headline block displaying the H1, and b) uncheck the Disable Title option in the sidebar settings. More info on Block Elements - Page Hero here:
https://docs.generatepress.com/article/block-element-page-hero/
You can of course delete that Element - but be minded you also have the Header Merge element which is what merges the content with the Site Header / Nav.
https://docs.generatepress.com/article/block-element-page-hero/
So you may need to exclude pages or posts from that,
2. No - the Theme can't store 'variables' - you would need to create some Custom Fields to store those values in the Post Meta. You can either use WPs built in Custom Fields or a plugin like ACF. Or there are some dedicated Meta/schema plugins specifically for that.
And appreciate the kind feedback.
Hi and thank you for getting back.
I had the chance to research my question a bit better, i meant is it possible to use: https://docs.generatepress.com/article/page-header-template-tags/
However I don't think it will work within the generatepress 'hook' element wp_hook. Figured I should double check.
I'd like to do something like this for the hook wp_hook in the <head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [{
"@type": "Question",
"name": "{{post_title}}",
"acceptedAnswer": {
"@type": "Answer",
"text": "{{custom_field.bodytag}}"
}
}
]}
</script>
Where I ideally in the the page's <h1> and <body> I think I'd have to create a custom field.
My question:
- With existing generate press tags, is it possible to do this in the <head>?
- how would i create a custom field for the <body> If thats at all possible?
Your other suggestion worked great as well. I just disabled the header, but the background appears to be white. Any quick smart ideas? Video in the area thing.
Thanks!!
1. The merging of the content:
Look for the Element tilted:
Header Merge
This is what merges the site header with whatever is at the top of the content.
So if you disable the Block Element on the Archives you will want to edit the Header Merge element and Exclude the same archives.
2. The JSON LD
Template Tags eg. {{post_title}} are only available in the Header Element so you won't be able to add them inside a hook element.
You would do something like this:
<?php
$title = get_the_title();
$answer = get_post_meta( get_the_ID(), 'faq_answer', true );
$json = '<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [{
"@type": "Question",
"name": "'. $title .'",
"acceptedAnswer": {
"@type": "Answer",
"text": "'. $answer .'"
}
}
]}
</script>';
// If $answer has a value then output the schema
if ($answer) {
echo $json;
}
?>
This line is where we get the custom field with a name of: faq_answer :
$answer = get_post_meta( get_the_ID(), 'faq_answer', true );
Hey thanks alot! I hope my videos are quick and painless :-D
Glad to be of help