Usage
nebula()->post_author($icon, $linked, $force)
Parameters
$label
(Optional) (Boolean) Whether to show the "icon", "text" or not
Default: icon
$linked
(Optional) (Boolean) Whether it should be linked
Default: true
$force
(Optional) (Boolean) Force the data regardless of Nebula Options
Default: false
Demo
Using post_meta:
Using individual Nebula post meta functions with options:
Other Nebula meta functions:
Source File
Located in /libs/Functions.php on line 671.
2 Hooks
Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.
Filters
"pre_nebula_post_author""nebula_post_author_defaults"
Need a new filter hook? Request one here.
Actions
This function has no action hooks available. Request one? public function post_author($options=array()){
$override = apply_filters('pre_nebula_post_author', null, $options);
if ( isset($override) ){return $override;}
$defaults = apply_filters('nebula_post_author_defaults', array(
'label' => 'icon', //"icon" or "text"
'linked' => true, //Link to author page
'force' => false, //Override author_bios Nebula option
));
$data = array_merge($defaults, $options);
//Include support for multi-authors: is_multi_author
if ( ($this->get_option('author_bios') || $data['force']) && get_theme_mod('post_author', true) ){
$label = '';
if ( $data['label'] === 'icon' ){
$label = '<i class="nebula-post-author-label fa-solid fa-user"></i> ';
} elseif ( $data['label'] === 'text' ){
$label = '<span class="nebula-post-author-label">Author </span>';
}
//Get the author metadata
$author_id = get_the_author_meta('ID');
if ( empty($author_id) ){ //Author ID can be empty outside of the loop
global $post;
$author_id = $post->post_author;
$author_name = get_the_author_meta('display_name', $author_id);
} else {
$author_name = get_the_author();
}
if ( $data['linked'] && !$data['force'] ){
return '<span class="posted-by" itemprop="author" itemscope itemtype="https://schema.org/Person">' . $label . '<span class="meta-item entry-author"><a href="' . get_author_posts_url($author_id) . '" itemprop="name">' . $author_name . '</a></span></span>';
} else {
return '<span class="posted-by" itemprop="author" itemscope itemtype="https://schema.org/Person">' . $label . '<span class="meta-item entry-author" itemprop="name">' . esc_html($author_name) . '</span></span>';
}
}
}
Override
To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):
add_filter('pre_nebula_post_author', 'my_custom_post_author', 10, 4); //The last integer must be 1 more than the actual parameters
function my_custom_post_author($null, $label, $linked, $force){ //$null is required, but can be ignored
//Write your own code here
return true; //Return true to prevent the original function from running afterwords
}
You can completely disable this PHP function with a single line actions:
add_filter('pre_nebula_post_author', '__return_false');