• Resolved John

    (@casinobike)


    Hi everyone!
    Web Stories plugin automatically generates “Archives: Stories” title in archive page. To fix this issue and remove the word “Archives:” you can just add the filter in functions.php of your particular theme. The result will be a title with only the word “Stories”

    //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;    
        });
    

    But if you want to customize the title, adding other words, better create the custom template of archive.php page of your wordpress theme.
    In my case, I created the additional page called archive-web-story.php by copying all the code from the original archive.php

    For this purpose another filter has been added in the functions.php

    function archive_web_story_template( $template, $template_type, $post ) {
        if ( ! is_singular() && 'web-story' === get_post_type() && ! is_post_type_archive( 'web-story' ) ) {
            $template = get_theme_file_path( 'archive-web-story.php' );
        }
    
        return $template;
    }
    add_filter( 'single_template', 'archive_web_story_template', 10, 3 );
    

    Then in archive-web-story.php page I replaced the original <h1> tag with the modified one:

    <h1><?php _e('Web', 'text-domain-name'); ?> <?php the_archive_title( '', '' );?></h1>
    

    Here you can see the example of my website.

    Warning: only for users with advanced knowledge in wordpress code programming. Before making modifications it is important to create backup files!

    • This topic was modified 3 years, 9 months ago by John.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Pascal Birchler

    (@swissspidy)

    Thanks a lot for sharing, although you do seem to make it a bit complicated ??

    > Web Stories plugin automatically generates “Archives: Stories” title in archive page.

    Note that WordPress is generating the titles, not the plugin.

    > To fix this issue and remove the word “Archives:” you can just add the filter in functions.php of your particular theme. The result will be a title with only the word “Stories”

    You could simplify this like so:

    add_filter(
    	'get_the_archive_title',
    	static function ( $title ) {
    		if ( is_post_type_archive( 'web-story' ) ) {
    			return 'Stories';
    		}
    		return $title;
    	}
    );

    > In my case, I created the additional page called archive-web-story.php by copying all the code from the original archive.php
    > For this purpose another filter has been added in the functions.php

    You don’t need any filter for this!

    If archive-web-story.php exists in your theme, WordPress will automatically load it.

    Thread Starter John

    (@casinobike)

    Hi Pascal!
    Thank you very much for your reply!
    Yes, you are right is WordPress generates the title “Archives:”, “Tag:” and others. Therefore I have added the filter to remove those titles not only from Web Stories but also from all the categories and tags of the theme.

    I have tried different options and for my case the filter from before works better. Although of course it can be simplified with your example so that it applies only to the Web Stories plugin.

    What it is about archive-web-story.php page. You are also right. I have removed the second filter and WordPress still load it correctly. Although I honestly don’t understand what filter hooks does it?

    Plugin Author Pascal Birchler

    (@swissspidy)

    > What it is about archive-web-story.php page. You are also right. I have removed the second filter and WordPress still load it correctly. Although I honestly don’t understand what filter hooks does it?

    That’s how the the WordPress template hierarchy works

    Thread Starter John

    (@casinobike)

    Thank you Pascal for your answer!
    Receive my congratulations for the plugin, good job. I personally and I think all the other users would like you to keep improving this wonderful plugin! Good luck!

    Plugin Author Pascal Birchler

    (@swissspidy)

    @casinobike Thanks a lot! We’re definitely working hard every day to make this plugin better.

    If you have a spare moment, could you perhaps consider leaving a review? The team would greatly appreciate it!

    Thread Starter John

    (@casinobike)

    @swissspidy Yes, of course, it’s done!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[NSFW] Change Web Stories Archive Page Title’ is closed to new replies.