I need to display a “custom author”, created with custom field, in place of the WordPress user who entered the post. I add this code in my functions.php file to replace the author’s name with the text that i put in a custom field called “autore”:
add_filter( 'the_author', 'guest_author_name' );
add_filter( 'get_the_author_display_name', 'guest_author_name' );
function guest_author_name( $name ) {
global $post;
$author = get_post_meta( $post->ID, 'autore', true );
if ( $author )
$name = $author;
return $name;
}
WordPress recognizes the code and it shows the “custom author” (created with the custom field) while the theme keeps showing the name of the WordPress users that have entered the post.
Plus i need to show a page with all the posts associated with the custom author (like an archive page).
Thanks
Hi creativit, I think that it will be more easy to use a dedicate plugin for guest author, like this one Molongui Author Box, Guest Author & Co-Author.
I hope this will help you!
Unfortunately, i can’t use a plugin because i installed Newspaper in an existing site (with more than 4000 posts) that already used the “custom field” method for guest authors. WordPress and default WordPress themes recognize the code, the problem is with Newspaper.
Hi,
If you want to use the custom fields, then you need to add the code in functions.php in this file path wp-content/plugins/td-composer/legacy/Newspaper/functions.php or better set it in child theme, after that go in a post and add the new custom filed -> https://i.imgur.com/PV6YhJY.png set the guest-author and set the value for it -> https://i.imgur.com/kAXOu2B.png the results will be -> https://i.imgur.com/wzujZ0j.png
I hope this will help you!
The website already used the “custom field method” for guest authors and all the posts already have the guest-author custom field.
The problem is this:
– If i use the “single post author box” module or the “single post author” module sometimes they show the custom author (created with the custom filed) and sometimes the WordPress user that entered the post, depending on where I place it in the single post template.
– If i use the “Flex block” modules to show all the post in my homepage or in a post category template they always keep showing the name of the WordPress users that have entered the post.
This makes me think that the script works but the theme cannot always “read” this information.
Hi,
Inside the post/article for me is working correctly, the name of author how publish the post is display only if there is no guest author set in custom field (at least for me is working like this).
Now, about the blocks and flex blocks, those are custom elements and the author name from them have a different structure, the code for that part is set here wp-content/plugins/td-composer/legacy/common/wp_booster/td_module.php => https://i.imgur.com/GrRjkiC.png and it need some custom changes to can display the guest author name on blocks.
Thank you!
Ok thanks for the explanation!
The information shown in the screenshot is very useful to me!
Thanks!
Hi,
i changed the code in wp-content/plugins/td-composer/legacy/common/wp_booster/td_module.php file and now everything works. But i have a doubt: if I update the theme and the composer, I lose the changes made to the file td_module.php? Can I overwrite the module file with my child theme to avoid losing the changes?
I found your tutorial about child theme (https://forum.tagdiv.com/the-child-theme-support-tutorial/) and it said that I can overwrite modules files of the wp-content\plugins\td-standard-pack\Newspaper\includes\modules folder by copying them into the child theme under this folder structure (…\child_theme_name\includes\modules\).
But the module file I’ve changed is located in a different folder. What folder structure should I create in the child theme to overwrite the td_module.php file?
Thanks
I can’t set the actual path (wp-content/plugins/td-composer/legacy/common/wp_booster/td_module.php) because the “plugins” folder is outside the “themes” folder.
Can you be more specific?
I suppose I have to create a new folder structure in the child-theme folder.
Maybe something like this: wp-content/themes/child_theme_name/td-composer/legacy/common/wp_booster/td_module.php?
Or how should I structure it?
can you ask your developers if there is another way to make the module “flex block” recognize the custom fields? so that we can write the change in the child theme and we don’t have to redo everything with every theme update.
Thanks
Hi creativit,
For the moment those files are not covered by child theme, and I do not know the implementation that it need to be done to do it, but I think that this can be done on custom work, the developers from there should be able to do it.
Thank you!
