I have a custom field in the theme Customizer that allow to define own copyright information. I created a shortcode displaying the current year. How to make the shortcode work when someone has pasted it into textarea?
I use Kirki framework to create theme options.
Kirki::add_field( 'my_customizer', array(
'type' => 'editor',
'settings' => 'copyright',
'label' => __( 'Content', 'mytheme' ),
'section' => 'section_footer',
'default' => __( 'Copyright ⓒ All rights reserved.', 'mytheme' ),
'description' => __( 'You can use [current-year] shortcode if you want.', 'mytheme' ),
) );
To display above option I add this to footer.php:
echo Kirki::get_option( 'my_customizer', 'copyright' );
What I see on the site:
Copyright ⓒ [current-year] All rights reserved.
All rights reserved. ⓒ [current-year] by XYZ
All rights reserved. ⓒ 2016 - [current-year]
What I need to achieve:
Copyright ⓒ 2019 All rights reserved.
All rights reserved. ⓒ 2019 by XYZ
All rights reserved. ⓒ 2016 - 2019
Any solution / idea? Thanks!
I have a custom field in the theme Customizer that allow to define own copyright information. I created a shortcode displaying the current year. How to make the shortcode work when someone has pasted it into textarea?
I use Kirki framework to create theme options.
Kirki::add_field( 'my_customizer', array(
'type' => 'editor',
'settings' => 'copyright',
'label' => __( 'Content', 'mytheme' ),
'section' => 'section_footer',
'default' => __( 'Copyright ⓒ All rights reserved.', 'mytheme' ),
'description' => __( 'You can use [current-year] shortcode if you want.', 'mytheme' ),
) );
To display above option I add this to footer.php:
echo Kirki::get_option( 'my_customizer', 'copyright' );
What I see on the site:
Copyright ⓒ [current-year] All rights reserved.
All rights reserved. ⓒ [current-year] by XYZ
All rights reserved. ⓒ 2016 - [current-year]
What I need to achieve:
Copyright ⓒ 2019 All rights reserved.
All rights reserved. ⓒ 2019 by XYZ
All rights reserved. ⓒ 2016 - 2019
Any solution / idea? Thanks!
Share Improve this question asked May 31, 2019 at 6:08 AvigoAvigo 377 bronze badges1 Answer
Reset to default 1If you have a shortcode string saved, try echoing it with do_shortcode
function, which turns shortcodes into content.
$saved_shortcode = get_option( 'my_customizer', 'copyright' );
if ( $saved_shortcode && is_string( $saved_shortcode ) ) {
echo do_shortcode( $saved_shortcode );
}
More about the function on the developer handbook, https://developer.wordpress/reference/functions/do_shortcode/
EDIT
Another option is just echo the year directly on the footer template without first getting the shortcode string from the database and then rendering it.