Mary Jane
Mary Jane

Reputation: 57

How can I get Wordpress user ID?

I want to use the Twitter follow button for site authors on all posts.

The Twitter structure is here:

<a href="https://twitter.com/twitterapi" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow @twitterapi</a>

Yes, it works but this place must be generic. I should import Wordpress $user->ID in this structure. How can I do this?

Upvotes: 0

Views: 1562

Answers (2)

Victory
Victory

Reputation: 5890

You can use get_current_user_id() in wordpress.

To get the author of the current post try the following

  <a href="https://twitter.com/<?php esc_attr_e(get_the_author()) ?>" 
     class="twitter-follow-button" 
     data-show-count="false" data-lang="en">Follow @<?php echo get_the_author() ?></a>

Upvotes: 1

Danilo Paone
Danilo Paone

Reputation: 148

To get the ID of the current user logged you can simple user this wordpress function:

get_current_user_id()

To put it in whatever html code you should just open the tags where you need a dynamic value.

<a href="https://twitter.com/twitterapi" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow <?php get_current_user_id() ?></a>

or using shortcut tags:

<a href="https://twitter.com/twitterapi" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow <?=get_current_user_id()?></a>

Upvotes: 0

Related Questions