0

My custom plugin is broken into two parts: a frontend.php and admin.php for loading code conditionally. Here is a rough outline of the code:

<?php
/*
My plugin info here
*/

if (is_admin()) {
  include_once('admin.php');
} else {
  include_once('frontend.php');
}

?>

I have written several shortcodes for use in pages and posts. In which file (admin.php or frontend.php) should code related to shortcodes be placed?

0

Shortcodes are processed on display so the code must be available on the front end when the shortcode is processed. Superficially, that means frontend.php.

I have never tried to split shortcode code in this way. You may have trouble splitting it off from the backend. The add_shortcode function is in wp-includes/shortcodes.php which loads for both back and front, suggesting that it is at least possible that it is needed on the back end. I'd have to run some experiments...

  • I am testing it now. I put the entire shortcode-related code into frontend.php (the handler function as well as the add_shortcode line) and it seems to be working as expected. I will test some more later but I think it can stay there. – JimmyPena Aug 5 '13 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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