I have been searching for a way to better manage dates on a WordPress website. I work at a college whose website is on WordPress. One issue we continuously run into is out of dates for reoccurring events. For instance, there is the start and end of registration, start and end of semester, any given holiday, this list goes on and on. Each of those dates change at some interval. My programmer brain thinks there must be away to set a reference to a particular reoccurring dates in page text, hypothetically it might look something like this.

The first day of semester: <?=START_OF_CURRENT_SEMESTER_SHORT/?>.
The semester began on <?=START_OF_CURRENT_SEMESTER_LONG/?>.

and those values would be set somewhere which might look like this:

$START_OF_SEMESTER_LONG = 'August 24, 2021'

Output would be displayed like this

The first day of semester: 07/24/2021.
The semester began on August 24, 2021.

Is there built-in way to accomplish something in line with my hypothetical example? Are there other plugins that might help with this type of concern?

1 Answer 1


You could, hypothetically, use placeholders in the content of a page (or a post), and then use the the_content filter to update the placeholders on the fly.

For example, the content of your page would be something like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

First date of semester: ##START_OF_SEMESTER_LONG##
First date of semester (short): ##START_OF_SEMESTER_SHORT##

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Then you would filter it like this when the page is loaded.

// I'm assuming $start_of_semester is a Unix timestamp,
// stored as an option, or post_meta, or anywhere you want.
add_filter( 'the_content', 'wpse404081_set_dates' );
 * Sets the appropriate dates in the page content.
 * @param  string $content The page content.
 * @return string          The filtered page content.
function wpse404081_set_dates( $content ) {
    $start_of_semester = get_option( 'start_of_semester' ); // for example.
    $content = str_replace(
        array( date( 'F j, Y', $start_of_semester ), date( 'm/d/Y', $start_of_semester ),
    return $content;

For information on how to set up the 'Start of Semester' option (aka "setting"), check out WordPress' Settings API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.