How can I add Page Tiles to my templates?

I’ve tried the code snippet described here, but it’s not working. Any ideas? Thank you.

Hi Richard,

Please try with this code instead:

function add_title() { ?>
         <header class="entry-header mbm">
            <h1 class="entry-title"><?php the_title(); ?></h1>
          </header>
 <?php
}
add_action( 'x_before_the_content_begin', 'add_title', 10 );

Or you can use the dynamic content feature, and pull the page title:

Hope it helps :slight_smile:

Awesome. Looks great. I take it the other snippet had a bit of extra <PHP tags? All set.

Actually. One question, I need to get this into a page template container. It’s floating all the way left. Do you have any parts of the manual where I can read about doing this?

I can edit the Blank Container, Header Footer template? Oh, I see it’s a reference to the Stack code. Where is the best place to read about that?

Thanks!

// =============================================================================
// TEMPLATE NAME: Blank - Container | Header, Footer
// -----------------------------------------------------------------------------
// A blank page for creating unique layouts.
//
// Content is output based on which Stack has been selected in the Customizer.
// To view and/or edit the markup of your Stack’s index, first go to “views”
// inside the “framework” subdirectory. Once inside, find your Stack’s folder
// and look for a file called “template-blank-1.php,” where you’ll be able to
// find the appropriate output.
// =============================================================================

x_get_view( x_get_stack(), ‘template’, ‘blank-1’ );

Actually, the code above works on all pages except the Home Page. It floats all the way left.

Hello Richard,

You will need to edit the PHP code and use this instead:

function add_title() { ?>
        <div class="x-section">
			<div class="x-container max width">
				<header class="entry-header mbm">
		        	<h1 class="entry-title"><?php the_title(); ?></h1>
		        </header>
			</div>
		</div>
 <?php
}
add_action( 'x_before_the_content_begin', 'add_title', 10 );


We would loved to know if this has work for you. Thank you.

Thanks. I tried this and it’s still showing the “Home” title on the home page. I guess I should also filter that out somehow?

Rich

Hey Rich,

Please update the code to:

function add_title() { 
    if( !is_home() ) :
?>
        <div class="x-section">
			<div class="x-container max width">
				<header class="entry-header mbm">
		        	<h1 class="entry-title"><?php the_title(); ?></h1>
		        </header>
			</div>
		</div>
 <?php
    endif;
}
add_action( 'x_before_the_content_begin', 'add_title', 10 );

Hope this helps.

That’s wonderful. I was going to look up how to do that too. Saved me a step.

If you need anything else we can help you with, don’t hesitate to open another thread.

1 Like

Weird, for some reason that is not working. I’m still not filtering out the Home title on the first page. Any ideas? This last code is in there.

Hey Richard,

Update the php code and use this:

function add_title() { 
    if( !is_home() || !is_front_page() ) :
?>
        <div class="x-section">
			<div class="x-container max width">
				<header class="entry-header mbm">
		        	<h1 class="entry-title"><?php the_title(); ?></h1>
		        </header>
			</div>
		</div>
 <?php
    endif;
}
add_action( 'x_before_the_content_begin', 'add_title', 10 );

For reference for the conditions:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.