Title: Create WordPress ShortCode
Last modified: March 30, 2024

---

# Create WordPress ShortCode

 *  [mutluksap](https://wordpress.org/support/users/mutluksap/)
 * (@mutluksap)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/create-wordpress-shortcode/)
 * Hello, I need a wordpress shortcode. The shortcode will work as follows: [get-
   button id=”1″] will return a template when used. I will use this shortcode in
   certain places on my page. For example, under a heading after the content, and
   again under a heading after the image. But the ids I call will be different everywhere.
   Like [get-button id=”4″]. What I want here is to collect all the ids and send
   a request to an API, then add my buttons to the places where I added the shortcode
   with the response returned from the API. How can I do that? For each button, 
   I can send a request to an API and return a template based on the response. However,
   I will use at least 10 button shortcodes on my page, so I do not want to request
   the API 10 times. Thank you in advance for your answers.

Viewing 1 replies (of 1 total)

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/create-wordpress-shortcode/#post-17539280)
 * Your request is less about a shortcode, you rather need a complete concept to
   realise your idea. I would suggest the following procedure:
 * Use Custom Post Types (CPT) to save the data from each API request as data records.
   To do this, you must first create the CPT: [https://developer.wordpress.org/reference/functions/register_post_type/](https://developer.wordpress.org/reference/functions/register_post_type/)
   
   Then you have to implement the API request, at first it is probably enough if
   you build a button in the backend that queries all API data when clicked. For
   the query, I would recommend using WordPress’ own functions for HTTP requests,
   e.g. [https://developer.wordpress.org/reference/functions/wp_remote_get/](https://developer.wordpress.org/reference/functions/wp_remote_get/)(
   or post, depending on what the API requires). You then create the queried data
   as data records of the CPT, i.e. via: [https://developer.wordpress.org/reference/functions/wp_insert_post/](https://developer.wordpress.org/reference/functions/wp_insert_post/)
 * Make sure not to save existing API data again but to update it.
 * As a result, you should then have one data record of your CPT for each API request.
 * Then define the shortcode. The ID as a parameter then corresponds to an entry
   in the CPT. You use it to access the data to be displayed, which is stored there,
   and output it using a template you have designed.
 * That would be my suggestion for the procedure.

Viewing 1 replies (of 1 total)

The topic ‘Create WordPress ShortCode’ is closed to new replies.

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [threadi](https://wordpress.org/support/users/threadi/)
 * Last activity: [2 years, 2 months ago](https://wordpress.org/support/topic/create-wordpress-shortcode/#post-17539280)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
