Rodrigo
Rodrigo

Reputation: 37

How to use the Rest API from wordpress in my post?

I am learning to create wordpress plugins. I am trying to create a plugin that basically allow the user favorite a post or not using the Rest API. I would like that my plugin allow to admin put a tag like that: Tag

And when the user publish the post, show the favorite tag this way:

love tag

Someone can help me?

Upvotes: 0

Views: 335

Answers (1)

Tommy Pradana
Tommy Pradana

Reputation: 134

The "tag" that you are talking about is a shortcode tag. You can read this https://codex.wordpress.org/Shortcode_API how to create your own shortcode in WordPress.

This is the example code based on your case:

<?php
function add_favorite_shortcode() {
   global $post;
   $post_id = $post->ID;
   $output = '<a class="add-to-favorite" data-post-id="' . $post_ID . '">♥ Add to favorites</a>';
   return $output;
}
add_shortcode( 'favoritar', 'add_favorite_shortcode' );

Add the function above in your plugin php file.

Upvotes: 1

Related Questions