Skip to content

Commit 0bcf424

Browse files
author
infinitnet
committed
first release
1 parent 2c70336 commit 0bcf424

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
WordPress plugin that adds shortcodes for current, published, and last modified year and month.
33

44
## Purpose
5-
The main purpose of this plugin is to dynamically add dates to post titles. The shortcodes also work in meta descriptions (Rank Math and Yoast) and post content.
5+
The main purpose of this plugin is to dynamically add dates to post titles. The shortcodes also work in meta descriptions (Rank Math, Yoast, SEOPress) and post content.
66

77
## Available Shortcodes
88
- **[currentmonth]** - current month
@@ -16,4 +16,5 @@ The main purpose of this plugin is to dynamically add dates to post titles. The
1616
The WordPress Date Shortcodes plugin is compatible with:
1717
- Rank Math
1818
- Yoast SEO
19+
- SEOPress
1920
- Contextual Related Posts (CRP)

wordpress-date-shortcodes.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Plugin Name: WordPress Date Shortcodes
4+
* Description: Adds shortcodes for current, published, and last modified year and month.
5+
* Author: Infinitnet
6+
* Author URI: https://infinitnet.io/
7+
* Plugin URI: https://github.com/infinitnet/wordpress-date-shortcodes
8+
* Update URI: https://github.com/infinitnet/wordpress-date-shortcodes
9+
* Version: 1.0
10+
* License: GPLv3
11+
* Text Domain: wordpress-date-shortcodes
12+
*/
13+
14+
// Shortcode functions for current year and current month
15+
if ( ! function_exists( 'infinitnet_current_year_shortcode' ) ) {
16+
function infinitnet_current_year_shortcode() {
17+
return date_i18n( 'Y' );
18+
}
19+
add_shortcode( 'currentyear', 'infinitnet_current_year_shortcode' );
20+
}
21+
22+
if ( ! function_exists( 'infinitnet_current_month_shortcode' ) ) {
23+
function infinitnet_current_month_shortcode() {
24+
return date_i18n( 'F' );
25+
}
26+
add_shortcode( 'currentmonth', 'infinitnet_current_month_shortcode' );
27+
}
28+
29+
// Shortcode to display the published year
30+
if ( ! function_exists( 'infinitnet_published_year_shortcode' ) ) {
31+
function infinitnet_published_year_shortcode() {
32+
global $post;
33+
return get_the_date('Y', $post->ID);
34+
}
35+
add_shortcode( 'publishedyear', 'infinitnet_published_year_shortcode' );
36+
}
37+
38+
// Shortcode to display the published month
39+
if ( ! function_exists( 'infinitnet_published_month_shortcode' ) ) {
40+
function infinitnet_published_month_shortcode() {
41+
global $post;
42+
return get_the_date('F', $post->ID);
43+
}
44+
add_shortcode( 'publishedmonth', 'infinitnet_published_month_shortcode' );
45+
}
46+
47+
if ( ! function_exists( 'infinitnet_modified_year_shortcode' ) ) {
48+
function infinitnet_modified_year_shortcode() {
49+
global $post;
50+
return get_the_modified_date('Y', $post->ID);
51+
}
52+
add_shortcode( 'modifiedyear', 'infinitnet_modified_year_shortcode' );
53+
}
54+
55+
// Shortcode to display the last modified month
56+
if ( ! function_exists( 'infinitnet_modified_month_shortcode' ) ) {
57+
function infinitnet_modified_month_shortcode() {
58+
global $post;
59+
return get_the_modified_date('F', $post->ID);
60+
}
61+
add_shortcode( 'modifiedmonth', 'infinitnet_modified_month_shortcode' );
62+
}
63+
64+
// Unified function to process meta content with shortcodes
65+
function infinitnet_process_meta_content( $content ) {
66+
return do_shortcode( $content );
67+
}
68+
69+
// Attach the function to filters for Rank Math, Yoast, and SEOPress
70+
add_filter( 'rank_math/frontend/title', 'infinitnet_process_meta_content' );
71+
add_filter( 'rank_math/frontend/description', 'infinitnet_process_meta_content' );
72+
add_filter( 'wpseo_title', 'infinitnet_process_meta_content' );
73+
add_filter( 'wpseo_metadesc', 'infinitnet_process_meta_content' );
74+
add_filter( 'seopress_titles_title', 'infinitnet_process_meta_content' );
75+
add_filter( 'seopress_titles_desc', 'infinitnet_process_meta_content' );
76+
77+
// Filters for processing shortcodes in Contextual Related Posts (CRP) plugin
78+
add_filter('crp_title', 'do_shortcode');
79+
add_filter('crp_thumb_title', 'do_shortcode');
80+
add_filter('crp_thumb_alt', 'do_shortcode');
81+
82+
// Filter for processing shortcodes in all titles
83+
function infinitnet_process_all_titles( $title ) {
84+
if ( ! is_admin() ) {
85+
return do_shortcode( $title );
86+
}
87+
return $title;
88+
}
89+
add_filter( 'the_title', 'infinitnet_process_all_titles' );

0 commit comments

Comments
 (0)