This repository contains a collection of useful WordPress shortcodes that can be easily added to your theme or custom plugin. Each shortcode is designed to address common needs in WordPress development.
To use these shortcodes in your WordPress site, you can do the following:
-
Clone this repository:
git clone https://github.com/danmaby/WordPress-Shortcodes.git
-
Include the
functions.php
file in your theme'sfunctions.php
or within a custom plugin:require_once "path/to/wordpress-shortcodes/functions.php";
-
Alternatively, copy specific shortcode files from the
shortcodes/
directory into your theme or plugin.
File: shortcodes/copyright-year.php
This shortcode displays the copyright symbol (©), the starting year, and the current year.
Usage:
[copyright_years start_year="2023"]
Example Output:
- If the current year is 2024 and the start year is 2023, the output will be:
© 2023–2024
. - If the current year is the same as the start year, it will display:
© 2024
.
Attributes:
start_year
: The year when your site was launched. Default is2020
.
File: shortcodes/url-parameter.php
This shortcode retrieves a specific parameter from the URL and displays its value in your WordPress content. It's useful for creating dynamic content based on query string parameters.
Usage:
[get_url_param param="your_parameter" default="Default Value"]
Example Output:
- If the URL is
https://example.com/page/?name=Dan
and you use[get_url_param param="name" default="Guest"]
, the output will be:Dan
. - If the
name
parameter is not present in the URL, the output will be:Guest
.
Attributes:
param
: The name of the URL parameter to retrieve. Required.default
: The default value to display if the parameter is not found in the URL. Optional, default is an empty string.
Contributions are welcome! If you have a shortcode that you think would be useful to others, feel free to open a pull request.
- Fork the repository.
- Create a new branch (
git checkout -b feature-shortcode-name
). - Add your shortcode in the
shortcodes/
directory. - Update the
README.md
with details about your shortcode. - Submit a pull request.
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.