# Creating custom shortcodes in WordPress

> Create your own WordPress shortcodes with a short PHP function so you can insert the same content in many posts and pages.

Source: https://helpcenter.ruachost.com/wordpress/guides/creating-custom-shortcodes-in-wordpress/

**Shortcodes** are small snippets that let you insert dynamic or repeatable content into posts, pages, or widgets. Instead of editing multiple pages individually, you can use a shortcode to display content consistently across your WordPress site. On **ruachost.com**, you can create custom shortcodes by adding PHP functions.

## Why Use Shortcodes?

- Simplify content management by reusing code.
- Add dynamic features (e.g., buttons, forms, banners).
- Reduce repetitive editing across multiple posts/pages.
- Improve flexibility without needing a plugin for every feature.

## Steps to Create a Custom Shortcode

1. **Log in to WordPress** with an administrator account.
2. In the dashboard, go to **Appearance → Theme Editor**.
3. Select your active theme and open the **functions.php** file.
4. Add the following code snippet:

   ```
   // Create a custom shortcode
   function ruachost_custom_shortcode() {
       // Change $message to the text you want to display
       $message = 'Here is the shortcode text.';
       return $message;
   }
   add_shortcode('my_custom_shortcode', 'ruachost_custom_shortcode');
   ```

   - Replace `'Here is the shortcode text.'` with your desired output.
   - Replace `'my_custom_shortcode'` with a unique shortcode name.
5. Save the file.
6. To use the shortcode, open a post or page and type:

   ```
   [my_custom_shortcode]
   ```
7. Publish or update the post → The shortcode output will appear where you placed it.

## Important Notes

- Always back up your theme before editing `functions.php`.
- Use a **child theme** to preserve changes during updates.
- Shortcodes must have unique names to avoid conflicts.
- You can create multiple shortcodes by repeating the process with different names/functions.
