Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
infinitnet committed Nov 17, 2023
1 parent 2c70336 commit 0bcf424
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
WordPress plugin that adds shortcodes for current, published, and last modified year and month.

## Purpose
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.
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.

## Available Shortcodes
- **[currentmonth]** - current month
Expand All @@ -16,4 +16,5 @@ The main purpose of this plugin is to dynamically add dates to post titles. The
The WordPress Date Shortcodes plugin is compatible with:
- Rank Math
- Yoast SEO
- SEOPress
- Contextual Related Posts (CRP)
89 changes: 89 additions & 0 deletions wordpress-date-shortcodes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Plugin Name: WordPress Date Shortcodes
* Description: Adds shortcodes for current, published, and last modified year and month.
* Author: Infinitnet
* Author URI: https://infinitnet.io/
* Plugin URI: https://github.com/infinitnet/wordpress-date-shortcodes
* Update URI: https://github.com/infinitnet/wordpress-date-shortcodes
* Version: 1.0
* License: GPLv3
* Text Domain: wordpress-date-shortcodes
*/

// Shortcode functions for current year and current month
if ( ! function_exists( 'infinitnet_current_year_shortcode' ) ) {
function infinitnet_current_year_shortcode() {
return date_i18n( 'Y' );
}
add_shortcode( 'currentyear', 'infinitnet_current_year_shortcode' );
}

if ( ! function_exists( 'infinitnet_current_month_shortcode' ) ) {
function infinitnet_current_month_shortcode() {
return date_i18n( 'F' );
}
add_shortcode( 'currentmonth', 'infinitnet_current_month_shortcode' );
}

// Shortcode to display the published year
if ( ! function_exists( 'infinitnet_published_year_shortcode' ) ) {
function infinitnet_published_year_shortcode() {
global $post;
return get_the_date('Y', $post->ID);
}
add_shortcode( 'publishedyear', 'infinitnet_published_year_shortcode' );
}

// Shortcode to display the published month
if ( ! function_exists( 'infinitnet_published_month_shortcode' ) ) {
function infinitnet_published_month_shortcode() {
global $post;
return get_the_date('F', $post->ID);
}
add_shortcode( 'publishedmonth', 'infinitnet_published_month_shortcode' );
}

if ( ! function_exists( 'infinitnet_modified_year_shortcode' ) ) {
function infinitnet_modified_year_shortcode() {
global $post;
return get_the_modified_date('Y', $post->ID);
}
add_shortcode( 'modifiedyear', 'infinitnet_modified_year_shortcode' );
}

// Shortcode to display the last modified month
if ( ! function_exists( 'infinitnet_modified_month_shortcode' ) ) {
function infinitnet_modified_month_shortcode() {
global $post;
return get_the_modified_date('F', $post->ID);
}
add_shortcode( 'modifiedmonth', 'infinitnet_modified_month_shortcode' );
}

// Unified function to process meta content with shortcodes
function infinitnet_process_meta_content( $content ) {
return do_shortcode( $content );
}

// Attach the function to filters for Rank Math, Yoast, and SEOPress
add_filter( 'rank_math/frontend/title', 'infinitnet_process_meta_content' );
add_filter( 'rank_math/frontend/description', 'infinitnet_process_meta_content' );
add_filter( 'wpseo_title', 'infinitnet_process_meta_content' );
add_filter( 'wpseo_metadesc', 'infinitnet_process_meta_content' );
add_filter( 'seopress_titles_title', 'infinitnet_process_meta_content' );
add_filter( 'seopress_titles_desc', 'infinitnet_process_meta_content' );

// Filters for processing shortcodes in Contextual Related Posts (CRP) plugin
add_filter('crp_title', 'do_shortcode');
add_filter('crp_thumb_title', 'do_shortcode');
add_filter('crp_thumb_alt', 'do_shortcode');

// Filter for processing shortcodes in all titles
function infinitnet_process_all_titles( $title ) {
if ( ! is_admin() ) {
return do_shortcode( $title );
}
return $title;
}
add_filter( 'the_title', 'infinitnet_process_all_titles' );

0 comments on commit 0bcf424

Please sign in to comment.