Making your proprietary shortcode doesn’t take long whatsoever. You don’t even need an more understanding of PHP to make basic shortcodes, so I’ve assembled a couple of easy steps on the best way to bulid a easy shortcode independent from anyone else. For example we are build RSS Subscription Shortcode.
Create Site Title Shortcode
This will help you to show your site title anywhere in your site it will not take a lot of time to make this simple code. just follow below step to make.
1. Create the Function in WordPress
The primary thing that you have to do is make the function for the shortcode inside your functions.php file. On another line, include the following code:
function site_title_function( $atts ){ $blog_title = get_bloginfo('name'); if(!empty($blog_title)) { echo $blog_title; } else { echo 'This is default title in case'; } }
2. Hooking into WordPress
Since the function has been made, now is the ideal time to hook into WordPress in order to associate the function with a shortcode. Here’s the code that needs to be added to the functions.php file:
add_shortcode( 'site_title', 'site_title_function' );
3. Call the Shortcode in WordPress
The last thing to do is to call the shortcode in WordPress. This is carried out inside the text editor of your post/page. For the above shortcode, we would include the following shortcode:
[ site_title ]
That’s it your custom shortcode is done…!!
Leave a Reply
You must be logged in to post a comment.