• Resolved tyealia

    (@tyealia)


    Hello, found some generatepress code that works great for posts to add date and tags and categories. Now I am using add categories to pages plugin and I want to display these on pages aswell. Thi following code works great for posts, and gives updated date to pages. What can I add to it to see my tags and categories on pages aswell?

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
        if ( is_single() ) {
            $items = array(
    	    'date',
    	    'author',
            'categories',
    	    'tags'
            );
        } return $items;
    } );
    
    add_action( 'generate_after_entry_header', 'tu_page_meta' );
    function tu_page_meta() {
        if ( is_singular( 'page' ) ) : ?>
            <div class="entry-meta">
                <?php generate_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @tyealia,

    Can you try modifying your current code to this one:

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
        if ( is_single() || is_page() ) {
            $items = array(
    	    'date',
    	    'author',
            'categories',
    	    'tags'
            );
        } return $items;
    } );
    
    add_action( 'generate_after_entry_header', 'tu_page_meta' );
    function tu_page_meta() {
        if ( is_singular( 'page' ) ) : ?>
            <div class="entry-meta">
                <?php generate_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif;
    }

    Hope this helps! Kindly let us know how it goes. 🙂

    Thread Starter tyealia

    (@tyealia)

    Works perfectly thank you so so much!

    Just one last question. It does this for every page, I have a bunch of privacy policies and about pages I don’t want it to display on. Is there a way to exclude from them? Even if I can exclude all pages tagged with Policies, or under a category like Policies that would work.

    I see.

    Here is a code you may try instead:

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
        if ( is_single() || is_page() && !is_page( 1431, 1112, 1113 ) ) {
            $items = array(
    	    'date',
    	    'author',
            'categories',
    	    'tags'
            );
        } return $items;
    } );
    
    add_action( 'generate_after_entry_header', 'tu_page_meta' );
    function tu_page_meta() {
        if ( is_singular( 'page' )  && !is_page( 1431, 1112, 1113 ) ) : ?>
            <div class="entry-meta">
                <?php generate_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif;
    }

    I added && !is_page( 1431, 1112, 1113 ) in your conditional statements.

    1431, 1112 and 1113 are just placeholders. Kindly replace this with the Page ID of the pages you wish to exclude.

    To get the page ID, you may edit the page and check the URL as such:

    https://share.getcloudapp.com/WnuyERlx

    https://share.getcloudapp.com/Z4u7wbqB

    You may also remove either && !is_page( 1431, 1112, 1113 ) if you would prefer it only on one of these functions.

    Hope this helps! 🙂

    Thread Starter tyealia

    (@tyealia)

    EDIT* found the issue with multiple pages by googling a bit, I added ( array after ispage and now it works! Thanks again fernando

    Hi Fernando, thanks a lot! it works for the first page I input, but any subsequent pages input do not work, have tested and it’s only always the first value # input that triggers. Maybe we used the wrong comma syntax or something?

    I appreciate your help thus far!!

    ex. of a second page entered in doesn’t remove

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
        if ( is_single() || is_page() && !is_page( 1040, 1042 ) ) {
            $items = array(
    	    'date',
    	    'author',
            'categories',
    	    'tags'
            );
        } return $items;
    } );
    
    add_action( 'generate_after_entry_header', 'tu_page_meta' );
    function tu_page_meta() {
        if ( is_singular( 'page' )  && !is_page( 1040, 1042 ) ) : ?>
            <div class="entry-meta">
                <?php generate_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif;
    }
    • This reply was modified 2 years, 3 months ago by tyealia.

    You’re right! Sorry about that, I forgot to put them in an array.

    Can you try this instead?:

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
        if ( is_single() || is_page() && !is_page( array(1040, 1042) ) ) {
            $items = array(
    	    'date',
    	    'author',
            'categories',
    	    'tags'
            );
        } return $items;
    } );
    
    add_action( 'generate_after_entry_header', 'tu_page_meta' );
    function tu_page_meta() {
        if ( is_singular( 'page' )  && !is_page( array(1040, 1042) ) ) : ?>
            <div class="entry-meta">
                <?php generate_posted_on(); ?>
            </div><!-- .entry-meta -->
        <?php endif;
    }

    Kindly let us know how it goes. 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding tags and categoreis to pages’ is closed to new replies.