Viewing 2 replies - 1 through 2 (of 2 total)
  • The function pointed out there is to get all the custom posts types that exist. You need to, during the WordPress post loop, find a way to grab the post type of the current post/page and display it. I haven’t seen anything that shows me in the WordPress post loop that there is a way to grab that information.

    I’d have to see your code to help you figure out why it isn’t showing. Also, do you have any kind of error logging turned on that might give you a clue as to why the code you found isn’t working?

    Thread Starter thetoolman123

    (@thetoolman123)

    Hi,

    Thanks for the reply.

    I have tried adding this snippet to the following code in my file that displays the title.

    <?php
    $args = array(
       'public'   => true,
       '_builtin' => false
    );
      
    $output = 'names'; // 'names' or 'objects' (default: 'names')
    $operator = 'and'; // 'and' or 'or' (default: 'and')
      
    $post_types = get_post_types( $args, $output, $operator );
      
    if ( $post_types ) { // If there are any custom public post types.
      
        echo '<ul>';
      
        foreach ( $post_types  as $post_type ) {
            echo '<li>' . $post_type . '</li>';
        }
      
        echo '<ul>';
      
    }
    ?>

    It works as in it lists all the types, but not a specific one.

    This is the code that controls my titles:

    <?php
    if ( !empty( $title_text ) ) {
        echo '<h1 class="stunning-header-title">' . esc_html( $title_text ) . '</h1>';
    } elseif ( is_home() ) {
        ?>
        <h1 class="stunning-header-title"><?php esc_html_e( 'Latest posts', 'crum-ext-stunning-header' ); ?></h1>
    <?php } elseif ( is_search() ) { ?>
        <span class="stunning-header-title h1 page-title">
            <?php printf( esc_html__( 'Search Results for: %s', 'crum-ext-stunning-header' ), '<h1 class="stunning-header-title d-inline">"' . get_search_query() . '"</h1>' ); ?>
        </span>
    <?php } elseif ( is_404() ) { ?>
        <h1 class="stunning-header-title"><?php esc_html_e( '404 Error Page', 'crum-ext-stunning-header' ); ?></h1>
        <?php
    } elseif ( function_exists( 'is_shop' ) && is_shop() ) {
        if ( is_shop() && apply_filters( 'woocommerce_show_page_title', true ) ) {
            ?>
            <h2 class="stunning-header-title h1"><?php woocommerce_page_title(); ?></h2>
        <?php } elseif ( is_product() ) { ?>
            <h2 class="stunning-header-title h1"><?php esc_html_e( 'Product Details', 'crum-ext-stunning-header' ); ?></h2>
            <?php
        } elseif ( is_cart() || is_checkout() || is_checkout_pay_page() ) {
            the_title( '<h1 class="stunning-header-title h1">', '</h1>' );
        }
    } elseif ( is_page() || is_singular( 'fw-portfolio' ) || is_singular( 'post' ) ) {
        the_title( '<h1 class="stunning-header-title">', '</h1>' );
    } elseif ( function_exists( 'tribe_is_event_query' ) && tribe_is_event_query() ) {
        ?>
        <h1 class="stunning-header-title"><?php esc_html_e( 'Events', 'crum-ext-stunning-header' ); ?></h1>
        <?php
    } elseif ( is_archive() ) {
        ?>
        <h1 class="stunning-header-title"><?php the_archive_title(); ?></h1>
        <?php
    } elseif ( is_tax() ) {
    	//FORUM TITLES
        echo '<h1 class="stunning-header-title">' . esc_html( get_queried_object()->name ) . '</h1>';
    } else {
        the_title( '<h1 class="forum-title stunning-header-title">', '</h1>' );
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Displaying page or post type?’ is closed to new replies.