php - WordPress child theme's template file doesn't have <h1> tag

Pages like author page on our WordPress site are missing tag. Since the pages are being rendered by the default template index.php, I'm looking for a way to add tag in it. Below is index.php. Test code like echo $thumb . $alttext; doesn't seem to work not because the variable doesn't hold any value, but the code itself isn't working.

<?php get_header(); ?>

<div id="main-content">
    <div class="container">
        <div id="content-area" class="clearfix">
            <div id="left-area">
        <?php
            if ( have_posts() ) :
                while ( have_posts() ) : the_post();
                    $post_format = et_pb_post_format(); echo $post_format; ?>

                    <article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' ); ?>>

                <?php
                    $thumb = '';

                    $width = (int) apply_filters( 'et_pb_index_blog_image_width', 1080 );

                    $height    = (int) apply_filters( 'et_pb_index_blog_image_height', 675 );
                    $classtext = 'et_pb_post_main_image';
                    $titletext = get_the_title();
                    $alttext   = get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true );
                    $thumbnail = get_thumbnail( $width, $height, $classtext, $alttext, $titletext, false, 'Blogimage' );
                    $thumb     = $thumbnail["thumb"];

                    echo $thumb . $alttext;

                    et_divi_post_format_content();

                    if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) {
                        if ( 'video' === $post_format && false !== ( $first_video = et_get_first_video() ) ) :
                            printf(
                                '<div class="et_main_video_container">
                                    %1$s
                                </div>',
                                et_core_esc_previously( $first_video )
                            );
                        elseif ( ! in_array( $post_format, array( 'gallery' ) ) && 'on' === et_get_option( 'divi_thumbnails_index', 'on' ) && '' !== $thumb ) : ?>
                            <a class="entry-featured-image-url" href="<?php the_permalink(); ?>">
                                <?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
                            </a>
                    <?php
                        elseif ( 'gallery' === $post_format ) :
                            et_pb_gallery_images();
                        endif;
                    } ?>

                <?php if ( ! in_array( $post_format, array( 'link', 'audio', 'quote' ) ) ) : ?>
                    <?php if ( ! in_array( $post_format, array( 'link', 'audio' ) ) ) : ?>
                        <h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <?php endif; ?>

                    <?php
                        et_divi_post_meta();

                        if ( 'on' !== et_get_option( 'divi_blog_style', 'false' ) || ( is_search() && ( 'on' === get_post_meta( get_the_ID(), '_et_pb_use_builder', true ) ) ) ) {
                            truncate_post( 270 );
                        } else {
                            the_content();
                        }
                    ?>
                <?php endif; ?>

                    </article>
            <?php
                    endwhile;

                    if ( function_exists( 'wp_pagenavi' ) )
                        wp_pagenavi();
                    else
                        get_template_part( 'includes/navigation', 'index' );
                else :
                    get_template_part( 'includes/no-results', 'index' );
                endif;
            ?>
            </div>

            <?php get_sidebar(); ?>
        </div>
    </div>
</div>

<?php

get_footer();

Answer

Solution:

I'll try to be a little more pr?�cise in my answer that the comment allow me :)

When you want to customize your template or create a custom one, in Wordpress, you have 3 prossibilities :

1 - The WRONG way

You directly edit the templates files in your theme.

Why is this wrong? Because template, like plugins, are regularely updated, so if you directly edit your template's files, you risk to loose all your customisations when you'll update it.

To avoid this, you can create that we called a "child theme" in Wordpress.

2 - Create a Child theme

Simpliy putting, it is a nice solution to avoid the issue encountered on the point 1 ;)

A child theme inherit of the parent theme's functions and allow you to make some customizations/addition to it without the risk of loosing it (since when you update the parent theme, the child theme isn't touched).

Here is a complete tutorial of the principle: https://developer.wordpress.org/themes/advanced-topics/child-themes/

Note: imoo this require some level of knowledge in PHP because a wrong change can break you site.

3 - Using a theme builder

This is your case : on your site is installed the theme DIVI which allow you to customize you theme and create custom templates with no (or few at least) skills in developpment required.

This is why it is called a "theme builder". To name a few : Divi, Elementor, ...

Again in that case you can directly use the main theme or create a child theme (which is highly recommended).

That being said (wrote), to return to your situation, you found out that the file you need to edit is the "index.php". I doubt that because it seems to be an author page, so more likely "author.php"

Why?

Because in fact, ALL pages are processed by the "index.php" file as it is the central template file, but if a template corresponding to the content type exist in you theme it will be use instead (index.php is just a fallback in case you theme don't include a custom file for any particular case).

See this article for more information about template hierarchy: https://developer.wordpress.org/themes/basics/template-hierarchy/

BUT, since you use a theme builder, you do not need to edit thoses files.

As you are using Divi, I suggest you to watch some tutorials on how the theme builder works in practice.

In short, inside the template builder interface of Divi, you can create template(s), that you can affect to any type of content.

This video should guid you on the right direction: https://www.elegantthemes.com/documentation/divi/the-divi-theme-builder/

Hope it helps.

Source