But I was thinking of making it a plugin rather than a theme. How can I achieve that?
2 Answers
There is no difference. This is a complete shortcode plugin:
/* Plugin Name: blogname */
add_shortcode( 'blogname', 'get_bloginfo' );
Usually, you should never register shortcodes in a theme, because the content will be useless after a a theme switch. So, a plugin is the better option.
-
You're absolutely right. I'm a dumbass x_x (it's somehow working now) May 20, 2013 at 12:39
Totally agree with toscho but I would use a must-use plugin in this case. In this way nothing will prevent shortcode from executing because Must-Use plugins can not be deactivated through WordPress admin.
-
I disagree. Must-use plugins should be reserved for very few use cases: super-important functionality that keeps the site running. Shortcodes don’t fall under this category.– fuxia ♦May 21, 2013 at 7:06
-
That' s kinda a point. But if plugin is deactivated or if function is deleted in functions.php you'll get [shortcode] on your posts. That's what you want ?– JMauMay 21, 2013 at 11:48
-
It is ugly, but not critical. On the other hand: when a shortcode callback returns an error message after an upgrade, you probably want to turn it off fast.– fuxia ♦May 21, 2013 at 11:50
-
"not critical" < depends. I mean ok this would not take the site down but let's say you use more than 1 shortcode in your post this could be hard for reading not to mention UX.– JMauMay 21, 2013 at 12:08