Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I wrote my first ShortCode in a file called: myShortCodes.php.

Does the add_shortcode go in the same PHP file as the ShortCode itself? Where do I upload it? How does WordPress know to look in my file?

I don't have to modify \wp_includes\shortcodes.php do I?

So far I have tried uploading myShortCodes.php to

  1. wp-includes/myShortCodes.php

  2. wp-content/themes/mytheme/skeleton/myShortCodes.php

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

In general, special theme functionality (including shortcodes) should be placed in your theme's functions.php file, which is in the root of your theme folder. If the code is less than a few dozen lines, it probably won't be worth creating a separate file (unless you just really want to organize your code that way).

So the shortcode functionality and the add_shortcode() call should be in functions.php.

Let's say you do want to separate it though. You can include your myShortCodes.php file like this in your functions.php file:

require_once('myShortCodes.php');

And then you can have the code (including the add_shortcode() call) kept in myShortCodes.php.

It's recommended to not alter the WordPress core files (like wp-includes/shortcodes.php) or put anything in the wp-includes folder because then it's outside of your theme folder and any upgrades to the WP core will cause your changes to be lost.

share|improve this answer
add comment

Your all your shortcode functions should either go in functions.php or a plugin file or be include'd/require'd from one of them.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.