• Resolved Chris

    (@lamordnt)


    I want to make the page header show the taxonomy term for the custom post type single post instead of the title of the post. I am trying to use the following code but it isn’t inserting the title in the correct place.

    
    // Change page title on custom post type single posts
        function disable_title( $return ) {
            if ( is_singular( 'study_findings') ) {  // 'study_findings' is the custom post type
                $return = false;
    $terms = get_the_terms( $post->ID, 'study' ); // 'study' is the custom taxonomy 
        if ( !empty( $terms ) ){
            // get the first term
            $term = array_shift( $terms );
            echo $term->name;
        }
            } 
           return $return;
        }
        add_filter( 'ocean_display_page_header', 'disable_title' );
    

    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter Chris

    (@lamordnt)

    Figured it out:

    // Example showing how to alter the page title, adjust accordingly to match your needs
    function my_alter_page_header_title( $title ) {
     
        // Change the posts title to their actual title
        if ( is_singular( 'study_findings') ) {
            $title = $terms;
    $terms = get_the_terms( $post->ID, 'study' ); // 'study' is the custom taxonomy 
        if ( !empty( $terms ) ){
            // get the first term
            $term = array_shift( $terms );
            echo $term->name;
           }
        }
     
        // Return the title
        return $title;
        
    }
    add_filter( 'ocean_title', 'my_alter_page_header_title', 20 );
Viewing 1 replies (of 1 total)
  • The topic ‘Change Page Header on Custom Post Single Posts to show Category’ is closed to new replies.