[Resolved] Move category meta

Home Forums Support [Resolved] Move category meta

Home Forums Support Move category meta

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #813684
    epickenyan

    Hi. Is there a way to move the category meta on blog layout to the inside of image like shown here http://prntscr.com/mms0nx?

    #814072
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Not super easily, but it should be do-able. Any chance you can link me to your site?

    #814205
    epickenyan

    Hi.

    #814736
    Tom
    Lead Developer
    Lead Developer

    First, add this PHP:

    add_filter( 'generate_category_list_output', '__return_false' );
    
    add_action( 'generate_before_content', function() {
        if ( is_archive() ) {
            $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
    
            if ( $categories_list ) {
                printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
                    _x( 'Categories', 'Used before category names.', 'generatepress' ),
                    $categories_list
                );
            }
        }
    } );

    Then, add this CSS:

    span.cat-links {
        margin-bottom: 30px;
        display: block;
        margin-top: -70px;
    }
    
    span.cat-links a {
        color: #fff;
        display: inline-block;
        background: #000;
        padding: 2px 5px;
    }
    
    .cat-links:before {
        display: none;
    }
    #814762
    epickenyan

    This is the result. http://prntscr.com/mnaa5d

    #814964
    Tom
    Lead Developer
    Lead Developer

    Hmm, that looks like the PHP isn’t working. How did you add it?

    Any chance I can see the site?

    #815112
    epickenyan

    I added to functions.php. Or should I have added it anywhere else? I didn’t know which hook to target specifically. The site link I did share up there.

    #815370
    David
    Staff
    Customer Support

    Hi there,

    just to test, can you try adding the code using the Code Snippets plugin, a link is contained within this article:

    https://docs.generatepress.com/article/adding-php/

    #815445
    epickenyan

    @david. The problem is not adding the code per se, but the output.

    #815451
    David
    Staff
    Customer Support

    The suggestion to try the Code Snippets plugin was to see if it the code worked and then we can look at why its not working within the Functions.php

    #815712
    epickenyan

    Just did. Result still as screenshot.

    #815801
    Tom
    Lead Developer
    Lead Developer

    Is it not possible to see the site itself to debug?

    This function specifically should be outputting something on the archives:

    add_action( 'generate_before_content', function() {
        if ( is_archive() ) {
            $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
    
            if ( $categories_list ) {
                printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
                    _x( 'Categories', 'Used before category names.', 'generatepress' ),
                    $categories_list
                );
            }
        }
    } );
    #815894
    epickenyan

    Are you not able to see this comment? I forgot to include a link in original post https://generatepress.com/forums/topic/move-category-meta/#post-814205. And just to be clear, are we still speaking about moving category to inside image as shared in the screenshot above?

    #816072
    Tom
    Lead Developer
    Lead Developer

    Ugh, sorry – totally missed that.

    Try this:

    add_action( 'generate_before_content', function() {
        if ( is_archive() || is_home() ) {
            $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
    
            if ( $categories_list ) {
                printf( '<span class="entry-meta cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
                    _x( 'Categories', 'Used before category names.', 'generatepress' ),
                    $categories_list
                );
            }
        }
    } );
    #816312
    epickenyan

    That makes it appear twice on the homepage and archives. I will just mark this as resolved because I think it is not practical. Thanks for the help though. Appreciated.

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