Title: Code snippet wrong after upgrading PHP7.4 to PHP8.2
Last modified: January 13, 2024

---

# Code snippet wrong after upgrading PHP7.4 to PHP8.2

 *  Resolved [mahyulan](https://wordpress.org/support/users/mahyulan/)
 * (@mahyulan)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/code-snippet-wrong-after-upgrading-php7-4-to-php8-2/)
 * I am using a code snippet, that was provided on WPBeginners by WPCode. But the
   snippet not working anymore after upgrading to PHP8.2
   So the plugin correctly
   indicates an error (on the line printed in bold?!), but I hope someone can help
   why the code is not valid anymore.
 * The code is to create a shortcut to display todays date:
 * function wpb_date_today($atts, $content = null) {
   extract( shortcode_atts( array(‘
   format’ => ”), $atts ) );
 * **if ($atts[‘format’] == ”) {**
   $date_time .= date(get_option(‘date_format’));}
   else {$date_time .= date($atts[‘format’]);}return $date_time;}add_shortcode(‘
   date-today’,’wpb_date_today’);
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcode-snippet-wrong-after-upgrading-php7-4-to-php8-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/code-snippet-wrong-after-upgrading-php7-4-to-php8-2/#post-17343349)
 * Hi [@mahyulan](https://wordpress.org/support/users/mahyulan/),
 * From what I can see the only issue with your code seems to be that your browser
   changed the quotes from ‘ to **‘**
 * I recommend manually editing your code in WPCode and making sure your code only
   uses ‘ or ” where applicable.
 * On the WPBeginner site you can also double click on the code and copy-paste that
   way – it should keep the correct quotes that way.
 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/code-snippet-wrong-after-upgrading-php7-4-to-php8-2/#post-17343350)
 * If you can also share the error message that you are getting in WPCode it would
   be useful to pinpoint what is happening.
 *  Thread Starter [mahyulan](https://wordpress.org/support/users/mahyulan/)
 * (@mahyulan)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/code-snippet-wrong-after-upgrading-php7-4-to-php8-2/#post-17344374)
 * I checked the single quotes in the code and they are the “streight” ones, do 
   that should be OK.
   The error message that I get is:“Uncaught TypeError: Cannot
   access offset of type string on string”
 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/code-snippet-wrong-after-upgrading-php7-4-to-php8-2/#post-17344393)
 * Ok, thank you, we need to update that code – it’s throwing warnings for older
   PHP versions too.
 * Please replace it with the code below and we’ll make sure to update the code 
   on WPBeginner too.
 *     ```wp-block-code
       function wpb_date_today( $atts, $content = null ) {
       	$atts = shortcode_atts( array(
       		'format' => '',
       	), $atts );
   
       	$date_time = '';
   
       	if ( $atts['format'] == '' ) {
       		$date_time .= date( get_option( 'date_format' ) );
       	} else {
       		$date_time .= date( $atts['format'] );
       	}
   
       	return $date_time;
       }
   
       add_shortcode( 'date-today', 'wpb_date_today' );
       ```
   
 *  Thread Starter [mahyulan](https://wordpress.org/support/users/mahyulan/)
 * (@mahyulan)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/code-snippet-wrong-after-upgrading-php7-4-to-php8-2/#post-17344426)
 * Hello Mircea,
 * Yes, now it is working again 🙂
   Many thanks for helping me out (and others of
   course that are using the code from WPBeginner)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Code snippet wrong after upgrading PHP7.4 to PHP8.2’ is closed to new
replies.

 * ![](https://ps.w.org/insert-headers-and-footers/assets/icon-256x256.png?rev=2758516)
 * [WPCode - Insert Headers and Footers + Custom Code Snippets - WordPress Code Manager](https://wordpress.org/plugins/insert-headers-and-footers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-headers-and-footers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-headers-and-footers/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-headers-and-footers/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [mahyulan](https://wordpress.org/support/users/mahyulan/)
 * Last activity: [2 years, 4 months ago](https://wordpress.org/support/topic/code-snippet-wrong-after-upgrading-php7-4-to-php8-2/#post-17344426)
 * Status: resolved