• Resolved ptrulli

    (@ptrulli)


    Hey there, I have searched for this on the forum and although it was covered my theme is different than what I have read so I am reaching out for assistance.

    Basically, the title changes to Archives when I set the “blog” to post page.

    I would like to keep or edit the Archive title name. The below code is from the archive.php file – hoping that the solution is to change something in the code below.

    <?php
    /**
     * The template for displaying archive pages.
     *
     * @package HelloElementor
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    ?>
    <main id="content" class="site-main">
    
    	<?php if ( apply_filters( 'hello_elementor_page_title', true ) ) : ?>
    		<header class="page-header">
    			<?php
    			the_archive_title( '<h1 class="entry-title">', '</h1>' );
    			the_archive_description( '<p class="archive-description">', '</p>' );
    			?>
    		</header>
    	<?php endif; ?>
    <div class="page-content">
        <?php
        while ( have_posts() ) {
            the_post();
            $post_link = get_permalink();
            ?>
            <article class="post">
                <?php
                printf( '<h2 class="%s"><a href="%s">%s</a></h2>', 'entry-title', esc_url( $post_link ), wp_kses_post( get_the_title() ) );
                if ( has_post_thumbnail() ) {
                    printf( '<a href="%s">%s</a>', esc_url( $post_link ), get_the_post_thumbnail( $post, 'large' ) );
                }
                the_excerpt();
                ?>
            </article>
        <?php } ?>
    </div>
    
    <?php wp_link_pages(); ?>
    
    <?php
    global $wp_query;
    if ( $wp_query->max_num_pages > 1 ) :
        ?>
        <nav class="pagination">
            <?php /* Translators: HTML arrow */ ?>
            <div class="nav-previous"><?php next_posts_link( sprintf( __( '%s older', 'hello-elementor' ), '<span class="meta-nav">&larr;</span>' ) ); ?></div>
            <?php /* Translators: HTML arrow */ ?>
            <div class="nav-next"><?php previous_posts_link( sprintf( __( 'newer %s', 'hello-elementor' ), '<span class="meta-nav">&rarr;</span>' ) ); ?></div>
        </nav>
    <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello @ptrulli

    There are a coupe of ways you can achieve this, but the most straightforward would be to make a copy of this file in a child theme, and make the required changes there.

    The process required is to create a child theme, and then make a copy of the archive.php template file, making sure to place it in the same location in the child theme as it exists in the parent theme. Then, in that copy of the template file, replace the following code:

    the_archive_title( '<h1 class="entry-title">', '</h1>' );

    With the something like this

    echo '<h1 class="entry-title">' . 'Your Custom Title' . '</h1>';

    Replacing Your Custom Title with whatever you want.

    Then enable the child theme.

    This will hardcode the new title into the child theme’s archive.php and that title will be displayed on the archive page.

    The other way to do it is to use the get_the_archive_title filter in a custom plugin or themes functions.php, but for this use case, I’d recommend the child theme route.

    Thread Starter ptrulli

    (@ptrulli)

    Couldn’t I theoretically just hardcode this into the main theme without the child?

    Indeed you could, as long as the theme will never be updated by the theme author, or it’s a custom theme you’ve built yourself. If there is a chance the theme might be updated at some point in the future, then there’s a chance you will loose any changes, which is why the child theme option is suggested. As I don’t know the status of your theme, I went with the safest option.

    Thread Starter ptrulli

    (@ptrulli)

    Great thanks! I appreciate your response. I’ll hardcode for now, and know if it is ever updated, I can reference this post then.

    • This reply was modified 1 year, 6 months ago by ptrulli. Reason: Resolved

    No problem, glad I could help.

    If your question has been answered, we would love if you would mark this topic as resolved in the sidebar. This helps our volunteers find the topics that still need attention and more people will get helped, possibly like you did.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Archive Title Change to Blog’ is closed to new replies.