change-org-wordpress-shortcode

Insert the Change.org Petition Count and other Data in WordPress with Shortcode

Change is an online petition service that provides a fairly effective platform for lobbyists and activists to gather signatures and promote their cause. While Change provides what is effectively a freeware service, they’re a profit-driven and growing corporation despite the dot org smokescreen. The organisation claims its mission is to “empower people everywhere to create the change they want to see.”

This article will show you how to include Change data in your WordPress website. Initially written around showing just the petition count, I quickly added on the option of including other data since it’s all returned in the same JSON response and might possibly serve somebody. It should be noted that I have nothing to do with the petition referenced on this page; it was simply trending at the time the article was written.

Before the shortcode function will work, you must first register for an API Key here .

The Result

The most basic response is a single piece of data. For example, [change url="https://www.change.org/p/auburn-city-council-the-hon-paul-toole-mp-local-government-minister-sacksalimmehajer" type="signature_count"] will simply return 12630 (bolding is mine to highlight the result). To include the result in paragraph tags I would have included [p="1"]. Available data is detailed below.

To include more detailed data, omit the type attribute. So, [change url="https://www.change.org/p/auburn-city-council-the-hon-paul-toole-mp-local-government-minister-sacksalimmehajer"] will return:

Sign our petition on Change: #SackSalimMehajer Auburn Deputy Mayor Salim Mehajer has treated the community, law & council with great disrespect and his illegal activities sets a poor example for the community. The Auburn LGA… 12630 signatures (84% of our goal).

I’ve formatted the result in a very basic manner. It’s expected that you’ll build your own HTML around the data.

The Code

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Shortcode Attributes

apikey

Before the shortcode function will work, you must first register for an API Key here . It should be added to the shortcode function.

url

The URL is the URL of the petition page you with to reference. In our case, we’ve used this page for our example.

type

To show specific types of information, the type need to be defined in your shortcode. Available data is as follows: petition_id, title, status, url, overview, targets, letter_body, signature_count, image_url, category, goal, created_at, end_at, creator_name, creator_url, organization_name, organization_url.

p

To wrap a type result in paragraph tags, use p="1".

cache

Cache determines the amount of time the result will be stored locally in your WordPress database. If it’s a slow-moving petition, perhaps consider updating the result only a couple of times a day to minimise the number of requests make to the Change API ([cache="3600 * 12]).

Considerations

  • Consider changing the color of the result to either amber, yellow or green, or something similar, to illustrate how close you are to meeting a target. I included this myself but didn’t want to complicate the code with features most people wouldn’t use.
  • In our initial code we used a bar graph to represent the number of signatures as a percentage of our target. Again, this feature overcomplicated things. Any graphing service (or simple CSS) provides this kind of feature.
  • Our HTML for a detailed response is rather basic so it’s expected that you’ll design your own container.

Download the Code

Download the shortcode function here . Like us on Facebook for inevitable updates.

Shortt URL for this post:

Leave a Reply

Your email address will not be published. Required fields are marked *