Create a simple shortcode in WordPress

Use code snippet to create a simple WordPress shortcode. I have created a sample shortcode prefix-portfolio with 2 attributes.

Before use change:

  • Change the Prefix with your own unique prefix.
  • Change the prefix with your own unique prefix.

How to use?

  1. Create a new page and add shortcode.
  2. Open the page. It’ll show the output of the shortcode like below:

Code Snippet


Debug WordPress hook sequence

Debug WordPress hook sequence

How it works?

Add query parameter debug in URL e.g. https://<mysite>/?debug. It’ll show the list of hooks in sequence.

Code Snippet

Add post meta in post (custom post type) endpoint with Rest API

Add post meta in post (custom post type) endpoint with Rest API.


  • Change post-type with your post type slug.
  • Change prefix-meta-key with your post meta key which you want to include in Rest API Response.


Visit https://<mysite>/wp-json/wp/v2/<post-type>/ it show the stored data from meta key  prefix-meta-key in the Rest API response.



Get logged in user roles in WordPress

Get logged in user assigned roles. Use function  wp_get_current_user() to get the current/logged in user info.


print_r( prefix_get_current_user_roles() );

// Output:
// Array
// (
//     [0] => administrator
// )