Site logo

Archived topic

Customized Post Meta Tags

9 replies · Started by Jeff on November 13, 2021

Viewing posts 1–10 of 10

I have created two custom taxonomies called Publication and Columnist. I would like to display the values of these fields instead of the standard "author" tag used in each single post. Can you please advise me how to accomplish this?

So I tried to follow the example you provided and it is not working. Here is an example of what I tried.

`<?php
/**
* GeneratePress child theme functions and definitions.
*
* Add your custom PHP in this file.
* Only edit this file if you have direct access to it on your server (to fix errors if they happen).
*/

add_filter( 'generate_entry_meta_post_types', function( $types ) {
$types[] = 'columnist';

return $types;
} );

add_action( 'generate_post_meta_items', function( $item ) {
if ( 'portfolio-tags' === $item ) {
echo get_the_term_list( get_the_ID(), 'post_columnist', '', ', ' );
}
} );

add_filter( 'generate_header_entry_meta_items', function() {
return array(
'date',
'tags',
'post_columnist',
);
} );

Hi Jeff,

On this line:

add_action( 'generate_post_meta_items', function( $item ) {
if ( 'portfolio-tags' === $item ) {
echo get_the_term_list( get_the_ID(), 'post_columnist', ", ', ' );
}
} );

Try changing the line if ( 'portfolio-tags' === $item ) to if ( 'post_columnist' === $item ).

That worked - thanks.

No problem. :D

One more question - how can I put some text between values?

Right now, my code is as follows:

<?php
/**
 * GeneratePress child theme functions and definitions.
 *
 * Add your custom PHP in this file.
 * Only edit this file if you have direct access to it on your server (to fix errors if they happen).
 */

add_filter( 'generate_entry_meta_post_types', function( $types ) {
    $types[] = 'publication';

    return $types;
} );

add_action( 'generate_post_meta_items', function( $item ) {
    if ( 'post_publication' === $item ) {
        echo get_the_term_list( get_the_ID(), 'post_publication', '', ', '  );
    }
} );

add_filter( 'generate_entry_meta_post_types', function( $types ) {
    $types[] = 'columnist';

    return $types;
} );

add_action( 'generate_post_meta_items', function( $item ) {
    if ( 'post_columnist' === $item ) {
        echo get_the_term_list( get_the_ID(), 'post_columnist', '', ', '  );
    }
} );

add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'date',
        'tags',
        'post_publication',
        'post_columnist',
    );
} );

It generates this:

November 15, 2021 Fox NewsStaff

I want it to display like this:

November 15, 2021 from Fox News by Staff

Basically adding the word from in front of the publication and the word by in front of the columnist.

On this item:

add_action( 'generate_post_meta_items', function( $item ) {
    if ( 'post_columnist' === $item ) {
        echo get_the_term_list( get_the_ID(), 'post_columnist', '', ', '  );
    }
} );

You can try adding a "by" text.

Example:

add_action( 'generate_post_meta_items', function( $item ) {
    if ( 'post_columnist' === $item ) {
        echo ' by '.get_the_term_list( get_the_ID(), 'post_columnist', '', ', '  );
    }
} );

That worked great.

No problem. :D

This archived topic is closed to new replies.