custom page titles for categories

Home Forums Support custom page titles for categories

Home Forums Support custom page titles for categories

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #190765
    Susanne

    Hi there, I looked everywhere for this info and could not find it:
    I have created three custom post types for my portfolio. One of them has several categories. I want to display the category name as the title on my category archive page
    Right now it just says “Archive”. I know there is a simple way to do this.
    I see that there is a function that says <?php do_action( 'generate_archive_title' ); ?> in the archive template. So I think I have to add a filter for that function?
    Can you help? much appreciated

    #190895
    Tom
    Lead Developer
    Lead Developer

    Hmm, this is a tough one..

    You would have to do something like this I think:

    add_action( 'after_setup_theme','generate_taxonomy_title' );
    function generate_taxonomy_title()
    {
        if ( is_tax( 'tax-slug' ) ) {
            remove_action( 'generate_archive_title','generate_archive_title' );
            add_action( 'generate_archive_title','generate_custom_taxonomy_archive_title' );
        }
    }
    
    function generate_custom_taxonomy_archive_title()
    {
    ?>
        <header class="page-header<?php if ( is_author() ) echo ' clearfix';?>">
            <?php do_action( 'generate_before_archive_title' ); ?>
            <h1 class="page-title">
                Your title
            </h1>
            <?php do_action( 'generate_after_archive_description' ); ?>
        </header>
    <?php
    }

    Something along those lines..

    https://codex.wordpress.org/Function_Reference/is_tax

    #191067
    Susanne

    Thanks for your quick reply Tom. I am now thinking it would be better to make a custom page template that uses a filterable portfolio. That way I would not have to bother with archive titles at all. Will try to get some more info on that. I found a great link here:
    how-to-build-isotope-portfolio-in-your-wordpress-theme/
    Will try to make that happen and report back

    • This reply was modified 7 years, 11 months ago by Susanne.
    #191106
    Tom
    Lead Developer
    Lead Developer

    Cool πŸ™‚

    #214797
    Hans

    Hi Tom,

    I am a novice and not that familiar with PHP. I tried for some hours to bring your code to work. I believe that it has an error. I printed out some information and got the feeling that the hook is at the wrong place. When it is invoked the post seems to be not yet activated. I printed out the post-type and the tax an both where empty. By the way – there seems to be a coding error at the end of the snippet.

    Do you have an idea how the code could work correct and which hook should be used.

    #215046
    Tom
    Lead Developer
    Lead Developer

    Hi Hans,

    I just adjusted the code – sorry about that.

    Let me know if it works now πŸ™‚

    #215180
    Hans

    Hi Tom,

    unfortenately I did not succeed with your code. Either I got a syntax error or nothing happend using different hooks. I don’t know what I am making wrong. I use now a modification in template-tags.php at the end of the list of if … elseif which is working fine for me.

    elseif ( is_tax() ) :
    $tax = get_taxonomy( get_queried_object()->taxonomy );
    /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
    printf( __( '%1$s: %2$s', 'genratepress' ), $tax->labels->singular_name, single_term_title( '', false ) ) ;					
     
    #215332
    Tom
    Lead Developer
    Lead Developer

    If that’s working, copy the entire function you’re editing in template-tags.php (including the function_exists() wrapper) and add it to your functions.php in your child theme (or another method: https://generatepress.com/knowledgebase/adding-php-functions/).

    That will make it so you won’t lose your changes when you update πŸ™‚

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.