H1 and H2 above featured image

Hey,
on my site


I’d like to not only have the H1 but also an H2 above the featured image.
How can I achieve that?
Thanks!

Hi there,

The H1 tag is what you will add as the title of the blog post. But I am not sure what do you mean by H2? Would you please give us more detailed information with screenshots to know which section you mean by H2?

Thank you.

I’d like to have text between the H1 headline and the featured image (see screenshot. I’d like to be able to enter something like a subline (h2) where the red line is.

Thanks!

Hi There,

You should be able to achieve that if you follow the guide below.

1.Install ACF Pro plugin by head over to X -> Overview section. And then add a custom field as follows.

2.Then you will see that custom field when you Add/Edit new post.

3.Now create the file _content-post-header.php inside the following path in your child theme (/x-child/framework/views/renew/). Copy the following code into that file and save the changes (make sure that your child theme is activated).

<?php

// =============================================================================
// VIEWS/RENEW/_CONTENT-POST-HEADER.PHP
// -----------------------------------------------------------------------------
// Standard <header> output for various posts.
// =============================================================================

?>

<header class="entry-header">
  <?php if ( is_single() ) : ?>
  <h1 class="entry-title"><?php the_title(); ?></h1>
  <?php
  if (the_field('sub_post_heading')!=''){
  ?>
  <h2 class="my-sub-heading"><?php the_field('sub_post_heading'); ?></h2>
  <?php
  }
  ?>
  <?php else : ?>
  <h2 class="entry-title">
    <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_title(); ?></a>
  </h2>
  <?php endif; ?>
  <?php x_renew_entry_meta(); ?>
</header>

Hope that helps.

Hey,
thanks alot!
Only one thing that is not working.
The text is not wrapped in the h2? It’s wrapped in nothing.
(See screenshot)

Hi There,

Please update with the following code and it should work now.

<?php

// =============================================================================
// VIEWS/RENEW/_CONTENT-POST-HEADER.PHP
// -----------------------------------------------------------------------------
// Standard <header> output for various posts.
// =============================================================================

?>

<header class="entry-header">
  <?php if ( is_single() ) : ?>
  <h1 class="entry-title"><?php the_title(); ?></h1>

  <h2 class="h5 mtn my-sub-heading"><?php the_field('sub_post_heading'); ?></h2>

  <?php else : ?>
  <h2 class="entry-title">
    <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_title(); ?></a>
  </h2>
  <?php endif; ?>
  <?php x_renew_entry_meta(); ?>
</header>

Hope that helps.

Hey thanks alot just one thing here:
The first code that didn’t work tried it with “if”. I’d like to have this because not the code is working but it’s displaying an empty headline if I don’t enter anything. Could you give me the code that checks if the field is filled or not? thanks!

Hello There,

Thanks for updating in! To resolve your final issue, please have this line:

<h2 class="h5 mtn my-sub-heading"><?php the_field('sub_post_heading'); ?></h2>

Updated to this:

<?php $value = get_field('sub_post_heading');

<?php if ( $value || $value != '' ) : ?>
	
	<h2 class="h5 mtn my-sub-heading"><?php the_field('sub_post_heading'); ?></h2>

<?php endif; ?>

Hope this helps. Please let us know how it goes.

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