- This topic has 7 replies, 4 voices, and was last updated 1 week, 1 day ago by
David.
-
AuthorPosts
-
March 19, 2023 at 8:43 am #2573149
Philip
From what I see, the posts page by default does not include an h1 title. I can add it as a hook, which I did with the following:
<h1> <?php single_post_title(); echo ‘ – Page ‘. ( get_query_var(‘paged’) ? get_query_var(‘paged’) : 1 );?> </h1>But I would like this for the posts page, archives page, search results page. However, those already have h1 titles, so it won’t work if I just enable it from the Display Rules > Location.
Also, is there a way to modify to just show page numbers after page 1? Basically the goal is to eliminate duplicate h1 titles on the site.
Thanks
March 19, 2023 at 11:24 am #2573275Leo
StaffCustomer SupportHi Philip,
I believe you are looking for the
generate_element_display
with the is_paged() conditional tag
https://docs.generatepress.com/article/generate_element_display/You can see an example here:
https://docs.generatepress.com/article/generate_element_display/#display-an-element-to-the-first-page-of-archives-onlyAnd more examples in our forum:
https://generatepress.com/forums/search/is_paged%28%29/Let me know if this helps 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/March 19, 2023 at 12:43 pm #2573332Philip
Maybe. I might not be sure how to apply it. Basically, I want to show the page title as an H1 before the content.
For example on the Blog page, before it lists all the posts, I would want it to say “Blog”. So I created a hook element to
generate_before_main_content
. That works, but ideally I would have liked it to say page 1 of 100, etc.Also, was wondering how I can do the same for the archive pages as well.
March 19, 2023 at 5:36 pm #2573456Fernando Customer Support
Hi Philip,
To clarify, on Page 1, do you want to show the actual title? And, on page 2 onwards, show the Page number as the page title?
If you’re referring to something else, let us know.
March 19, 2023 at 7:35 pm #2573507Philip
That’s exactly it. I wanted to do it for the Blog, Category Archives, Author Archives, etc.
March 19, 2023 at 7:50 pm #2573510Fernando Customer Support
What you’re doing should be fine.
Create a Block Element for the Title on the first page. Then, add something like this:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 100 === $element_id && is_paged() ) { $display = false; } return $display; }, 10, 2 );
Replace
100
with your Element’s ID. Getting the Element ID: https://share.getcloudapp.com/YEuDdrnQAdding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Then, for your Hook Element where you’re adding your code, add this snippet as well:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 100 === $element_id && !is_paged() ) { $display = false; } return $display; }, 10, 2 );
Again, replace
100
with your Hook Element’s ID.March 20, 2023 at 7:17 am #2574119Philip
Got you. Would I be able to do that without the code snippets plugin? For example, just by enabling the “Execute PHP”? Because I tried that, and it didn’t work.
March 20, 2023 at 8:32 am #2574336David
StaffCustomer SupportHi there,
that code cannot be used in a GP Hook element.
It has to be added either using that plugin, or in a child theme.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.