Categories: wordpress

How To Create Shortcode in WordPress

WordPress Shortcode API

WordPress Shortcode API is complete set of methods that are used to create shortcodes in pages , posts and custom posts. For example, the following shortcode will add gallery with the attached images. Shortcode API enables developer to create specific content that a user cam insert into desired pages or posts.



The API Shortcode handles  both kind of shortcodes self-closing and enclosing shortcodes by crafty parsing, thus eliminating the need for writing a regular expression for each shortcode. Functions are included for setting and retrieving predefined attributes.

Here’s a minimal example of the PHP code required to create a shortcode in wordpress:

function demo_func( $atts ){
	return "foo and bar";
}
add_shortcode( 'demo', 'demo_func' );

This will create [demo] shortcode that returns as: foo and bar

admin

Share
Published by
admin

Recent Posts

How To Write Urdu in Photoshop

in Today's video tutorial we are going to learn how to write Urdu in photoshop…

3 months ago

Duplicate page in WordPress

Go to Dashboard > Plugins and search Duplicate pageNow install Duplicate Page plugin and active…

7 months ago

How to disable comments in WordPress

Comments are a great way to communicate with your audience, but some site owners don’t…

8 months ago

7 Types of Propaganda Techniques Advertisers Use

It is very common for advertisers and influencers to use propaganda techniques to get their…

8 months ago

How is NLP Changing the Way we do On-page SEO in 2020?

Google aims to provide improved and better search results for all of its users. For…

9 months ago

How to Create a Blog for Free and Make Money

The world is changing rapidly and so are the ways of earning money. Gradually, everything…

9 months ago