Frage

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!

War es hilfreich?

Lösung

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();

Andere Tipps

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;
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top