Site logo

Archived topic

Adding Page Title via GP Hook

7 replies · Started by Andy on October 13, 2016

Viewing posts 1–8 of 8

Hi Tom,

I'm trying to dynamically add all page titles except for home page just below the header by adding the following code to the After Header GP Hook:

<?php if ( ! is_front_page() ) : ?>

<div style="padding: 40px 0;background-color:#34788d;" class="page-banner">
         <div style="padding-left:50px;font-size:1.8em;color:white;" class="grid-container">
               <?php the_title(); ?>
         </div>
</div>

<?php endif; ?>

This is working great except on my portfolio page (set as my blog page) where it already displays the required page title by default (Portfolio) but my code is also adding another title it seems from the first post in the archive.

Whats the best way around this as I just want the 'Portfolio' title displayed.

URL: http://tinyurl.com/hj7mc59

You might need to update your conditional.

For example:

<?php if ( ! is_front_page() && ! is_home() ) : ?>

<div style="padding: 40px 0;background-color:#34788d;" class="page-banner">
         <div style="padding-left:50px;font-size:1.8em;color:white;" class="grid-container">
               <?php the_title(); ?>
         </div>
</div>

<?php endif; ?>

Working perfectly now thanks.

I've also just noticed another issue, in my customizer settings in Layout>Container I have top content padding set to 0, this seems to be working fine on standard pages as the entry-content class adds a 2em margin.
However, on single posts there is no padding/spacing at the top of the page: http://tinyurl.com/gurnh64
Whats the best way to make pages/posts have the same top content padding?.

Why not just add padding to the top in the Customizer?

I could but for standard pages there would be more spacing at the top (because of the + 2em margin) then on single posts.

You could always remove that margin when needed:

.entry-content {
    margin-top: 0;
}

Yeh decided to go with 30px in the customizer then used your CSS for everywhere else.

Awesome :)

This archived topic is closed to new replies.