9

I need to remove "Archive:" label from the archive page title. I tried this string without results:

<?php the_archive_title('<h2>','</h2>', false);?>

The title keeps displaying the "Archive:" label before the title. How can I get rid of it?

This is the full code of my page:

<?php get_header('inner');?>

    <div class="row large-uncollapse">
        <div class="columns small-12 medium-12 large-12">
            <div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">

              <?php if(function_exists('bcn_display'))
              {

                echo '<b>Sei in:</b>';
                bcn_display();
              }?>
            </div>

        </div>
    </div>

    <div class="row large-uncollapse">
        <div class="columns small-12 medium-12 large-12 large-centered text-center pad-vr-2">
          <?php echo get_the_archive_title();?>
        </div>
    </div>

<?php if(is_singular('rassegna-stampa')): ?>

    <div id="rassegna-stampa">
        <div class="row large-collapse">

          <?php
          if ( have_posts() ) :
            while ( have_posts() ) : the_post();
              echo '<div class="columns small-12 medium-6 large-4 float-left" style="margin-bottom:10px;">';
              echo '<div class="columns small-3 medium-3 large-3">';
              if(has_post_thumbnail()){
                echo the_post_thumbnail();
              }
              if( get_field('file') ) {
                echo '<a href="';
                the_field('file');
                echo '" data-featherlight="iframe" target="_blank">';
                echo '<button>';
                echo '<img src="';
                echo get_site_url();
                echo '/wp-content/uploads/2016/09/pdf.png" width="20px">';
                echo '</button>';
                echo '</a>';
              }
              if( get_field('link') ) {
                echo '<a href="';
                echo the_field('link');
                echo '" data-featherlight="iframe">';
                echo '<button>';
                echo '<img src="';
                echo get_site_url();
                echo '/wp-content/uploads/2016/09/link.png" width="20px">';
                echo '</button>';
                echo '</a>';
              }
              echo '</div>';
              echo '<div class="columns small-9 medium-9 large-9">';
              echo '<h3 style="margin:0px;">';
              echo the_title();
              echo '</h3>';
              echo '<small>';
              echo '—';
              echo the_field('testata');
              echo '</small>';
              echo '<small>';
              echo the_field('data');
              echo '</small>';
              echo '<span style="font-size:12px;">';
              the_excerpt();
              echo '</span>';
              echo '</div>';
              echo '</div>';
            endwhile;
          else :
            echo wpautop( 'Sorry, no posts were found' );
          endif;
          ?>
        </div>
    </div>


<?php else :?>

    <div id="libri">
        <div class="row large-collapse">

          <?php
          if ( have_posts() ) :
            while ( have_posts() ) : the_post();
              echo '<div class="columns small-12 medium-6 large-4 float-left" style="margin-bottom:10px;padding-bottom: 12px; height:220px;">';
              echo '<div class="columns small-3 medium-3 large-3">';
              if(has_post_thumbnail()){
                echo the_post_thumbnail();
              }
              echo '</div>';
              echo '<div class="columns small-9 medium-9 large-9">';
              echo '<h3 style="margin:0px;">';
              echo the_title();
              echo '</h3>';
              echo '<div style="float:left;width:100%;">';
              echo '<small style="float:left;width:auto;">';
              echo the_field('anno_pubblicazione');
              echo '</small>';
              echo '<div style="float:left; line-height:15px;">';
              echo '&nbsp;—&nbsp; ';
              echo '</div>';
              echo '<small style="float:left;width:auto;">';
              echo the_field('editore');
              echo '</small>';
              echo '</div>';
              echo '<span style="font-size:12px;">';
              the_excerpt();
              echo '</span>';
              echo '</div>';
              echo '<div class="columns small-12 medium-12 large-6">';
              echo '<a href="';
              the_permalink();
              echo '">';
              echo '<button style="width:auto; padding:0.4rem; float:left; border:1px #000 solid;">';
              echo 'Leggi tutto';
              echo '</button>';
              echo '</a>';
              echo '</div>';
              echo '<div class="columns small-12 medium-12 large-6">';
              if( get_field('link_acquisto') ):
                echo '<a href="';
                echo the_field('link_acquisto');
                echo '" style="color:#D34D3D;">';
                echo '<button style="width:auto; padding:0.4rem; float:left; border:1px #D34D3D solid;">';
                echo 'COMPRA';
                echo '</button>';
                echo '</a>';
              endif;
              echo '</div>';
              echo '</div>';
            endwhile;
          else :
            echo wpautop( 'Sorry, no posts were found' );
          endif;
          ?>
        </div>
    </div>

<?php endif ;?>

<?php get_footer();?>

Thanks!

2

3 Answers 3

10

You need to use the filter get_the_archive_title. It works like the_title filter. More details about the function that embed the filter here

More in this question remove category tag

EDIT :

When it's a custom post type archive page, you might use another function to print the title : post_type_archive_title() Then you'll be able to hook in the title with the filter post_type_archive_title , but there is no prefix for this function.

So in your template replace the call to get_the_archive_title() function with:

post_type_archive_title();
7
  • 1
    Thanks for the reply. Unfortunately it doesn't work for me. It keeps diplaying "Archives:". I'm in the archive of a custom post type, can it helps?
    – Stefano
    Commented Nov 6, 2016 at 20:11
  • Anyone can help in any way?
    – Stefano
    Commented Nov 7, 2016 at 13:35
  • You need to look into your archive template. Update your question with its content. If you don't know which page is load, install query monitor plugin, it will provides all info.
    – Benoti
    Commented Nov 7, 2016 at 13:39
  • Thank you, I've just edited the answer with the entire code.
    – Stefano
    Commented Nov 7, 2016 at 13:42
  • I miss your first comment ! I edit my answer
    – Benoti
    Commented Nov 7, 2016 at 13:58
7

Also, you can remove unnecessary words from any standard title:

add_filter( 'get_the_archive_title', function ($title) {
  if ( is_category() ) {
    $title = single_cat_title( '', false );
  } elseif ( is_tag() ) {
    $title = single_tag_title( '', false );
  } elseif ( is_author() ) {
    $title = '<span class="vcard">' . get_the_author() . '</span>' ;
  } elseif ( is_tax() ) { //for custom post types
    $title = sprintf( __( '%1$s' ), single_term_title( '', false ) );
  } elseif (is_post_type_archive()) {
    $title = post_type_archive_title( '', false );
  }
  return $title;
});
1
3

If you look at the get_the_archive_title() function, the prefix is now (since WP 5.5.0) wrapped in its own filter (get_the_archive_title_prefix):

$prefix = apply_filters( 'get_the_archive_title_prefix', $prefix );
if ( $prefix ) {
    $title = sprintf(
        /* translators: 1: Title prefix. 2: Title. */
        _x( '%1$s %2$s', 'archive title' ),
        $prefix,
        '<span>' . $title . '</span>'
    );
}

So you could use the filter to return an empty string (or anything you want) to overwrite the 'Archive:' text:

add_filter( 'get_the_archive_title_prefix', '__return_empty_string');

or

add_filter( 'get_the_archive_title_prefix', function($prefix) {
    /*$prefix is available for processing, too*/
    return __('your custom prefix: ', 'theme-text-domain');
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.