Create Simple Shortcode Without Plugin in WordPress

Create Simple Shortcode Without Plugin to display dynamic content like the current year anywhere on your WordPress site. Here’s how to do it with a quick tweak.

Step 1: Add the Shortcode Code

Add this to your child theme’s functions.php:


// Create a simple [year] shortcode
function qdt_year_shortcode() {
  return date(‘Y’);
}
add_shortcode(‘year’, ‘qdt_year_shortcode’);

How It Works

This function registers a new shortcode [year] that outputs the current year dynamically anywhere in your posts or pages.

Why Create Simple Shortcode Without Plugin?

Using your own shortcodes keeps your site light and removes the need for heavy plugins for simple dynamic tasks.

Common Mistake

Always test your shortcode output and check for syntax errors when adding to functions.php.

Pro Tip

Use unique names for shortcodes to avoid conflicts with existing plugins or themes.

Related Snippet

If you liked this, check out my guide on removing the category base without a plugin in WordPress.

Leave a Comment