Bird
0
0

How can a plugin safely add a new shortcode that outputs the current year without modifying core files or themes?

hard📝 Application Q9 of 15
Wordpress - Plugins and Extensibility
How can a plugin safely add a new shortcode that outputs the current year without modifying core files or themes?
AModify WordPress core files to include the shortcode
BEdit the theme's footer.php to add PHP code for the year
CRegister the shortcode using add_shortcode() inside the plugin code
DUse JavaScript to insert the year after page load
Step-by-Step Solution
Solution:
  1. Step 1: Understand shortcode registration

    Plugins can register shortcodes using add_shortcode() function safely.
  2. Step 2: Avoid modifying core or theme files

    Editing core or theme files risks breaking updates and site stability.
  3. Step 3: JavaScript is not ideal for shortcode output

    Shortcodes are server-side; JavaScript runs client-side and is less reliable.
  4. Final Answer:

    Register the shortcode using add_shortcode() inside the plugin code -> Option C
  5. Quick Check:

    Shortcodes registered via add_shortcode() in plugins [OK]
Quick Trick: Use add_shortcode() in plugins for safe shortcode creation [OK]
Common Mistakes:
  • Editing theme or core files for shortcodes
  • Using JavaScript instead of PHP
  • Not registering shortcode properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes