It is very easy for WordPress site owners to add a Reddit login button to their site. Reddit is basically a social bookmarking website which allows website owners to post their content to it. It also provides users to give vote to any specific content and thus make it more popular among its readers.
Facebook, Google+, and Twitter buttons are used more frequently on website due to their growing popularity. But there are cases, where users demand more security and confidence when registering with your website. In such a scenario, you can create a Reddit button and provide them a safe and easy way to login with your site.
In this tutorial, I will give you an overview of the entire process of adding Reddit button to your WP powered website. The tutorial is easy to follow and will surely help you in getting your content submitted to Reddit. So, let’s get started.
1. Create a Reddit OAuth Library
To begin with, you need to create a Reddit OAuth Library which should be capable of managing all the tricky tasks related to Reddit OAuth login. The library will also create all the needed URLs for the Reddit login.
Once you are done with creating a library and necessary URLs, you’ll receive a zip file. Extract the file and start moving its content into your theme folder. The process will create a /inc directory within your theme folder with all the crucial files you need for the Reddit login.
This library also creates the necessary WordPress REST API URLs required for Reddit login.
2. Loading The Reddit OAuth Library into WordPress
In this step, you’ll need to start loading the library we have created in the previous step into your theme’s functions.php file and insert the following code in the same.
3. Redirect Your Visitors
Creating the sign in button isn’t enough, you need to redirect your users as well so that they could login easily. To redirect users use the following URL:
site_url() . "/wp-admin/admin-ajax.php?action=reddit_oauth_redirect"
The URL will help you manage all the core functionalities relating to redirecting your users. As soon as the user clicks on login, they will be navigated to your website homepage.
4. Installing the Reddit App
Here you need to create a Reddit app for the purpose of user authentication. Below are the steps mentioned to create the Reddit app.
1. Go to the Reddit app page
2. Click on “Create an app”
3. Start filling the form. Here, you’ll be asked about the type of app you want, select on the web app and then redirect URL to your site using site_url() . “/wp-admin/admin-ajax.php?action=reddit_oauth_redirect”.
Once you are done creating the Reddit app, you’ll receive an App ID and App Secret.
Now, start copying your username, app id, and secret key from the dashboard and save all of them and display them as options in your WordPress.
You can use the below mentioned option names and store them as values:
update_option("reddit_client_id", $client_id_variable); update_option("reddit_client_secret", $client_secret_variable); update_option("reddit_username", $app_name_variable);
And that’s all you need to do to add a reddit login button to your site.
In the next section, I will explain you the process of creating a Reddit login widget, so that you can showcase the Reddit login button to your visitors.
How to Create a Reddit Login Widget
Below I am providing a list of code which you can use with the plugin. However while doing so, make sure you have to integrate the Reddit OAuth library with your plugin.
Below is the description of this code:
• First of all, we have included the Reddit OAuth library<br ?–> • Next, we have created a widget displaying the Reddit login button and some essential input boxes on the backend.
• As soon as the user will submit the widget from the backend, all the values will be saved as WordPress options.
• And selecting the login button, the user will be redirected to the URL mentioned ( site_url() . ‘/wp-admin/admin-ajax.php?action=reddit_oauth_redirect’). The URL will be responsible for managing the login related functions.
Access Token is necessary to make Reddit Rest API calls. Use the following code to fetch the access token.
get_user_meta(get_current_user_id(), "reddit_access_token", true);
Sometimes while doing the process of making REST API calls, you get a Token Expiration error. To get rid of such error, call the function below:
Hopefully, you have now learned the process of creating a Reddit login button on your WordPress site. Depending on your theme, you can place the button anywhere you want. Follow WPArena on Reddit.
Easy Social Share Buttons for WordPress is all-in-one social share solution that allows you share, monitor and increase your social popularity. With Easy Social Share Buttons for WordPress you will take your social sharing and following on a next level.
Easy Social Share Buttons for WordPress allows you to use 20 of major social networks and in addition, you have Love this button, Send to mail and Print. Easy Social Share Buttons for WordPress also includes 12 native social like, follow and subscribe buttons which will increase your social following and social proof. The plugin gives you the freedom to control every aspect of the display but also we simplify the initial setting with easy to use configuration wizard.