Skip to Content

post_author()

Show the author post metadata.

PHP March 25, 2020

Usage

PHP
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

Request or provide clarification »

Demo


Using post_meta:
Using individual Nebula post meta functions with options:
Other Nebula meta functions:
  • Functions
  • No EXIF data found

Source File

Located in /libs/Functions.php on line 476.

1 Hook

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
"nebula_post_author_defaults"
Need a new filter hook? Request one here.

Actions
This function has no action hooks available. Request one?

Note: This function contains 1 to-do comment.

PHP
    public function post_author($options=array()){
        $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);

        //@todo "Nebula" 0: 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 fas fa-fw 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

This function can not be short-circuited with an override filter. Request one?