Upvote Posts

Add upvoting and a trending algorithm to WordPress.

Updated Dec. 29, 2024 (version 1.1.2) | DEMO | Tested with PHP 8

If you’re interested in adding features to your WordPress site similar to Reddit with upvoting and trending posts, then Upvote Posts is all you need. This plugin adds an upvote button to posts. Then using a combination of views and upvotes, it displays your trending posts when you add the following query to the end of your site’s base URL: /?q=trending

An example of the main blog posts list with the upvote button

Here’s how it works

After installing and activating, go to Settings -> Upvote Posts. By default, the upvote button and number of views will show after your post content on single pages (aka permalink pages). Check the first box in the settings to hide the automatic display if you’d like. Then you may show the upvote button anywhere by adding the Upvote Button block using the WordPress block editor.

Or, add the upvote button to a theme template file with PHP:

<?php
if ( function_exists( 'wilcosky_insert_upvote_button' ) ) {
    echo wilcosky_insert_upvote_button( '' );
}
?>

Or, use the shortcode: upvote_button

By default in the settings a view is worth 1 point and an upvote is 2 points. You may change these numbers and the trending algorithm will update and change your trending posts order. So, you get to decide if a view or upvote is worth more and how much more! 🆒

Remember, to view trending posts, add a menu item or link somewhere on your site that points to: /?q=trending

An image showing the settings page for this plugin.
Upvote Posts’ settings page

Upvote Posts turns your WordPress site into a mini Reddit, Digg, or other classic upvote style site.


Blocks

  • Search for “Upvote Button” when adding blocks in the block editor (Gutenberg)
  • Search for “Upvote Views” when adding bocks in the block editor (Gutenberg)

Shortcodes

  • upvote_button (with surrounding brackets of course)
  • upvote_views (with surrounding brackets of course)

Functions

  • wilcosky_insert_upvote_button
  • wilcosky_insert_upvote_views

Roadmap

Here are the changes I plan on making in the future:

  • Enhance how the blocks look in the editor (currently, there is a simple text placeholder)
  • If you have an idea, let me know.

Changelog

December 29, 2024 – v1.1.2

  • Fixed hidden PHP notice about stylesheet being enqueued too early

December 26, 2024 – v1.1.1

  • Ensure the views element works anywhere it is placed versus single pages only
  • Views template function, shortcode, and block added
  • Minor javascript and css adjustments

December 25, 2024 – v1.1.0

  • Added login message if user tries to vote while logged out
  • Simplified code that generates upvote button HTML
  • Created a function that can be used in template files instead of using the block or shortcode (wilcosky_insert_upvote_button)

December 20, 2024 – v1.0.0

  • Initial Release
Billy Wilcosky