I'm trying to add this code into my theme's function.php
function custom_add_author() {
$author = get_the_author();
echo $author;
}
add_action( '???', 'custom_add_author' );
I wanted to add this function code into the specific php named "author-listing.php"
How can I add this using the correct code? was it?
add_action( 'author-listing.php', 'custom_add_author' );
If i read your question right..you can just use include() function.
For example at the top of author-listing.php, you can add:
include("function.php");
If you ment a wordpress theme, take alook at the official documentation at: https://developer.wordpress.org/reference/functions/add_action/ there are some more examples as well.
To find out the number and name of arguments for an action, simply search the code base for the matching do_action() call. For example, if you are hooking into 'save_post', you would find it in post.php:
<?php do_action( 'save_post', $post_ID, $post, $update ); ?>
Your add_action call would look like:
<?php add_action( 'save_post', 'my_save_post', 10, 3 ); ?>
And your function would be:
function my_save_post( $post_ID, $post, $update ) { // do stuff here }