Site logo

Archived topic

Add meta to custom post type

24 replies · Started by Hilton on December 7, 2021

Viewing posts 16–25 of 25

Ah I see what you mean.

Can you tell us how and where you want it to be displayed?

Do you want it to appear on the Header Element? If that's the case, you'll need a shortcode to display the taxonomy term links.

We can write a quick shortcode for this if this is the case. Let us know.

One more thing, regarding placement, I don't think you need to worry because we can hook it using GP's "Elements" like we did here (generate_after_content) Elements: https://bit.ly/3Iwdv4R frontend: https://bit.ly/31BVyRx

Thanks

Hi Elvin,

It worked, the categories are being displayed. But the links are not active as you can see here https://bit.ly/31BVyRx . How can I activate the respective links?

Thanks

ah right, the shortcode specifically strips the link.

Let's modify the shortcode a bit:

Try this modification:

add_shortcode( 'my_terms', function( $atts ) {
    $options = shortcode_atts( array(
        'term' => 'category',
    ), $atts );

    $terms = get_the_term_list( get_the_ID(), $options['term'], '', ', ', '' );

    if ( ! is_wp_error( $terms ) ) {
        return $terms;
    }
} );

Now it worked! The only pending issue is to put it in the same format as the normal posts as you can see here in this print https://bit.ly/3IqVp4i and in this post for example https://bit.ly/3lNnZDv .

I think it uses the <span class="cat-links">

Thanks

We can modify it further to wrap it in that element.

Example:

add_shortcode( 'my_terms', function( $atts ) {
    $options = shortcode_atts( array(
        'term' => 'category',
    ), $atts );

    $terms = get_the_term_list( get_the_ID(), $options['term'], '', ', ', '' );

    if ( ! is_wp_error( $terms ) ) {
        return sprintf(
					'<span class="cat-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ',
					esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ),
					$terms,
					apply_filters( 'generate_inside_post_meta_item_output', '', 'categories' )
				);
    }
} );

I've included the icon as well.

Elvin, thank you very much! It worked here. Excellent!

No problem. Let us know if this is resolved or if you need further help. :D

This archived topic is closed to new replies.