• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WPArena

WPArena

WPArena is a premium online resource site of WordPress and is focused on providing excellent WordPress Tutorials, Guides, Tips, and Collections.

  • News
    • Opinion
  • Tutorials
  • Reviews
    • Themes
    • Plugins
  • Comparisons
  • Collections
    • Education Themes
    • Genesis Child Themes
    • Best Responsive Themes
    • Medical WordPress Themes
    • Finance & Business Themes
    • Crowdfunding Themes
  • Resources
    • Inspiration
  • Services
WPArena » Tutorials
Tutorials

A Detailed Guide on Adding a Reddit Button To Your WordPress Site

Avatar of Arslan Rashid Arslan Rashid Updated: July 6, 2022

FacebookTweetPinLinkedInEmailPrint

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.

require_once("inc/redditoauth.php"); 

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.

https://gist.github.com/WPArena/8f6be610066fed753e433216643eb2cb#file-reddit_button-php

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

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:

reddit_refresh_access_token();

Summing Up

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

Easy Social Share Buttons for WordPress
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.

This post was orginally published on: February 23, 2015 and was updated on: July 6, 2022.

Related Tags: Add Reddit Button Social Media Integration

FacebookTweetPinLinkedInEmailPrint

Related Stories

  • How To Add WordPress Themes From The Dashboard

    How To Add WordPress Themes From The Dashboard

  • WordPress Version 2.6 Now Available

    WordPress Version 2.6 Now Available

  • Exploring WordPress General Options Settings Panel

    Exploring WordPress General Options Settings Panel

Avatar of Arslan Rashid

Arslan Rashid

Arslan is an Electrical Engineering student who has a keen interest in the WordPress developments and upcoming technologies. He likes to share interesting knowledge with the readers.

Primary Sidebar

wordpress link categories

Utilizing The Flexibility Of WordPress Links Categories

Why less is more for WordPress plugins

Recent Topics

  • Official Windows 7 Wallpapers
  • How to secure your WordPress images and content from Theft
  • Top 20 Web Designing Companies in the World
  • WP Rocket Review: Is It the Perfect Solution for WordPress Caching?
  • The Complete WordPress Security Guide 2023 – Step by Step

Footer

Top

  • Services
  • Our Themes
  • Facebook
  • Twitter
  • Linkedin

Reviews

  • Beaver Builder Review
  • Beaver Themer Review
  • WP User Frontend Pro
  • Ninja Forms Review
  • MemberPress Review

More Reviews »

Resources

  • Best WordPress Plugins
  • WordPress Permalinks Structure
  • Email Management System
  • Envato Free Files
  • Advertise
  • Write for us
  • Disclosure
  • Terms
  • Privacy
  • Contact

Copyright © 2023 · All Rights Reserved · WPArena is a Project of TechAbout LLC.
We are not affiliated with Automattic or WordPress.

  • Advertise
  • Write for us
  • Disclosure
  • Terms
  • Privacy
  • Contact
Share this ArticleLike this article? Email it to a friend!

Email sent!