0

I have created a shortcode in WordPress to show next day date of a specific day but it does not show the correct date when I am passing the parameter through the shortcode. Can anyone tell me what I am missing here.

[recurring_event Short="Wed" Full="wednesday"]

function recurring_event_att( $atts ){
$date ='';
$default = array(
    'Short' => 'Sun',
    'Full' => 'sunday'
);
$eventday = shortcode_atts($default, $atts);
date_default_timezone_set('US/Eastern');
if(date('D') == $eventday["Short"]) { 
   echo date('F d, Y');
}
else {
  // Create a new DateTime object
  $date = new DateTime();

 // Modify the date it contains
  $date->modify('next '.$eventday['Full'].'');

  //output
  echo $date->format('F d, Y');
 }
}
// register shortcode
add_shortcode('recurring_event', 'recurring_event_att');

1 Answer 1

0

Use the parameters of the shortcode with lowercase: [recurring_event short="Wed" full="wednesday"]

Try to follow the next code:

// NAV: Custom Code
function wpcoder_recurring_event_att( $atts ){
$date ='';
$default = array(
    'short' => 'Sun',
    'full' => 'sunday'
);
$eventday = shortcode_atts($default, $atts);
date_default_timezone_set('US/Eastern');
if(date('D') == $eventday["short"]) { 
   echo date('F d, Y');
}
else {
  // Create a new DateTime object
  $date = new DateTime();

 // Modify the date it contains
  $date->modify($eventday['full']);
    
    $date->modify('+1 day');

  //output
  echo $date->format('F d, Y');
 }
}
// register shortcode
add_shortcode('recurring_event', 'wpcoder_recurring_event_att');

You can add the code in the file 'functions.php' or add using the free plugin WP Coder via the page Global PHP

1
  • Using lowercase my code is working now, thanks a lot
    – v morgesh
    Commented Dec 6, 2023 at 19:42

Your Answer

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

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