DO YOU NEED A CONTENT WRITER FOR YOUR BUSINESS?

Your One-Stop Solution for All Content Needs! Click here for more!
Categories: WordPress

Make a short code in WordPress

Share

Creating a short code in WordPress is not easy to implement and at the same time this is also essential for building a block.
But, using WordPress shortcode function, WordPress makes it simple to create.

Here, you will know how to create your own shortcode using a simple example.

Let’s make a plugin that display a text on any page or post.

In WordPress plugin, there is already a predefined shortcode function for creating a shortcode.

Read Also: Make a simple plugin – WordPress

So, using this shortcode function, you can define a handler function that parse the shortcode and then return the output.

First you need to register a shortcode using add_shortcode() method.

For e.g.

add_shortcode( <shortcode_name>, <handler_function>);

<shortcode_name> (required, string) : This is a string which to be searched in the post.

<handler_function> (required, callable) : This is a hook to run when a shortcode is found.

Make the shortcode in your plugin file or in function.php file so that this can be usable for all space.

<?php
/*
Plugin Name: Data Fetch
Plugin URI: http://www.namasteui.com
Description: WordPress collection data from database using a shortcode
Version: 1.0
Author: Namaste UI
Author URI: www.namasteui.com
*/
if ( !defined( 'WP_FD_ABSPATH' ) )
define( 'WP_FD_ABSPATH', plugin_dir_path( __FILE__ ) );

function wp_data_fetch(){
echo "Your functionalities here.";
}
add_shortcode('data_fetch', 'wp_data_fetch');
?>

(a) Create a function first called “function wp_data_fetch()”.
(b) Then using wordpress handler, “add_shortcode” define your function in it and in your admin post or Page use “data_fetch” as short code [data_fetch].
(c) As a result the value which is written will be showed on that post or page.

For more details click here.

Namaste UI

For any types of queries, you can contact us on info[at]namasteui.com.

Recent Posts

Understanding Battery Coating: Key Factors to Perfection

Battery coating is the process of applying uniform layers of active materials—such as cathode and…

45 minutes ago

Edge Computing vs Cloud Computing: What’s the Difference?

Let’s face it. Tech buzzwords get thrown around a lot—especially when it comes to how…

3 days ago

How Data Intelligence Shapes the Future of Digital Innovation

In today’s digital world, the boundaries between technology, finance, and innovation are rapidly disappearing. Businesses…

6 days ago

How To Power Your Backyard Parties with A Solar Power Battery?

Backyard gatherings like BBQs, family reunions, and garden parties are an exciting way to enjoy…

7 days ago

5 Best Practices for Programmatic Advertising

Marketers are always on the lookout for more effective ways to reach their target audiences.…

1 week ago

Are We All Addicted to Stimulation? The New Face of Anxiety Disorders

Does your phone control your mind more than you control your phone? Modern life exploits…

1 week ago