Site logo

Archived topic

Move category meta

19 replies · Started by epickenyan on February 18, 2019

Viewing posts 1–15 of 20

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?

Hi there,

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

Hi.

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;
}

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

Any chance I can see the site?

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.

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

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

Just did. Result still as screenshot.

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
            );
        }
    }
} );

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
            );
        }
    }
} );

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.

This archived topic is closed to new replies.