Created
April 29, 2025 05:58
-
-
Save xenioushk/a5d5fedbfab5ec3bbb1ce0f9cb0a658c to your computer and use it in GitHub Desktop.
Revisions
-
xenioushk created this gist
Apr 29, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ // Gather all the shortcode data. $shortcode_data = [ 'tag' => 'bwl_headline', 'title' => "Hello WordPress", 'sub_title' => "Generate dynamic wordpress shortcode.", ]; // Extract the shortcode data. // For destructuring array data, you can also use the php list function instead of extract. extract($shortcode_data); // Exclude the tag. $shortcode_attributes = array_diff_key( $this->faq_data, array_flip( [ 'tag', ] ) ); // Build the shortcode attributes string. $attributes_string = ''; foreach ( $shortcode_attributes as $key => $value ) { $attributes_string .= sprintf( '%s="%s" ', esc_attr( $key ), esc_attr( $value ) ); } // Generate the final shortcode string. // Output: [bwl_headline title="Hello WordPress" sub_title="Generate dynamic wordpress shortcode."] $shortcode_string = sprintf( '[%s %s/]', esc_attr( $shortcode ), trim( $attributes_string ) ); // Execute the shortcode. echo do_shortcode($shortcode_string);