sinanisler logo

Get Current Author ID on Author.php, Condition, Bricks Builder

with this custom data tag, you can show or hide your section/dom depending on your author.php author id easy to make custom designs for different people.

data tag: {current_author_id}

// Adds a new tag 'current_author_id' to the Bricks Builder dynamic tags list.
add_filter( 'bricks/dynamic_tags_list', 'add_current_author_id_tag_to_builder' );
function add_current_author_id_tag_to_builder( $tags ) {
    $tags[] = [
        'name'  => 'current_author_id',
        'label' => 'Current Author ID',
        'group' => 'Author Data',
    ];

    return $tags;
}

// Retrieves the current author ID on an author archive page.
function get_current_author_id() {
    return is_author() ? get_queried_object_id() : '';
}

// Renders the 'current_author_id' tag by fetching the current author ID.
add_filter( 'bricks/dynamic_data/render_tag', 'render_current_author_id_tag', 10, 3 );
function render_current_author_id_tag( $tag, $post, $context = 'text' ) {
    if ( $tag === 'current_author_id' ) {
        return get_current_author_id();
    }
    return $tag;
}

// Replaces the '{current_author_id}' placeholder in content with the actual current author ID.
add_filter( 'bricks/dynamic_data/render_content', 'render_current_author_id_in_content', 10, 3 );
add_filter( 'bricks/frontend/render_data', 'render_current_author_id_in_content', 10, 2 );
function render_current_author_id_in_content( $content, $post, $context = 'text' ) {
    if ( strpos( $content, '{current_author_id}' ) !== false ) {
        $author_id = get_current_author_id();
        $content = str_replace( '{current_author_id}', $author_id, $content );
    }
    return $content;
}

edit the user to see which user have which id number

Leave the first comment