Dynamic Shortcodes is a tool that allows you to create and use "shortcodes" within your WordPress content. You can think of Dynamic Shortcodes as a placeholder for a dynamically generated value.
Basic Example of Dynamic Shortcodes
Retrieving the Current Post's Title
The {post:title}
shortcode can be used to fetch and display the title of the post in which it is embedded. When you insert this shortcode into your content, the Dynamic Shortcodes plugin recognizes it and replaces it with the actual title of the post.
Hello, you're reading "{post:title}"!
If the current post’s title was "Snorkeling Guide", the displayed result would be:
Hello, you're reading "Snorkeling Guide"!
Expanding the Possibilities with Dynamic Shortcodes
Dynamic Shortcodes are not limited to simple data retrieval; they can be used to implement complex logic and data manipulation. Here are some advanced ways to use them, explained in simple terms:
Use a Dynamic Shortcode to show different messages depending on who is viewing the page. For instance, you might display a personalized welcome message to administrators versus non-registered users.
Example{if:
{and:
{eq:{acf:gender} 'female'}
{lt:{acf:age} 25}}
'Youth Female Category'
'Other Categories'
}In this example, if the
gender
field, created with Advanced Custom Fields, is 'female' and theage
field is less than 25, 'Youth Female Category' is displayed. Otherwise, 'Other Categories' is shown.Display titles of the last three posts from a specific category. This demonstrates how Dynamic Shortcodes can be used to dynamically fetch and display results from complex queries.
Example{loop:{query:posts}
[{post:title} by {post:author}]
@sep=', '
}Here, the
{query}
shortcode is nested within a{loop}
shortcode to iterate over posts and display the title and author of each.Advanced Formatting
Display the publication date and time of a post in a specified format, using a Dynamic Shortcode to fetch the post's publication date and format it according to a specified date and time format. This example demonstrates how to use nested shortcodes to perform simple but powerful operations
Example
Publication date: {date:{post:date}@format='d-m-Y H:i'}
In this example, the{date}
shortcode is used to retrieve and format the publication date of the current post. The@format
key argument specifies the date and time format, showcasing how Dynamic Shortcodes can manage and display date information precisely.