Placing raw HTML inside a WordPress shortcode

For the sake of having @Milo’s comment as an answer. Your code works as it should, it is just not possible to “write” HTML in the visual editor also in shortcodes. Shorcodes are not treated differently then any other text. If you want formatted HTML in your shortcode you just need to use the normal … Read more

Shortcode to generate and save password in a file

Per the comment under the OP’s question, below is the solution by using a return instead of an echo: add_shortcode( ‘phptest’, ‘custom_shortcode_phptest’ ); function custom_shortcode_phptest() { // Add Shortcode function generatePassword( $length = 6 ) { $characters=”0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”; $charactersLength = strlen( $characters ); $pass=””; for ( $i = 0; $i < $length; $i++ ) { $pass … Read more

Error do_shortcode In WooCommerce Template

I solved this with dirty way.. hope someone else can provide more efficient solution, my final working code for problem above: $shortkode=”[zendesk_request_form size=”3″ group=”extra-field” subject=”Quotation For -wkwkwk-“]”; $shortkode = do_shortcode( $shortkode ); add_action(‘woocommerce_single_product_summary’, ‘quotation_form’, 61); function quotation_form() { $produk = get_the_title(); global $shortkode; $shortkode = str_replace(“-wkwkwk-“, $produk, $shortkode); echo $shortkode; } So i move out … Read more

Pass javascript array to shortcode

You’re going to have other problems than the brackets because shortcode_parse_atts will have already parsed your attributes, and the various single and double quotes will confuse the regular expression used to do that. If you need the exact string, perhaps you could get it from a custom field. Alternatively, and better, you could specify a … Read more

Can wp_localize_script be used within a shortcode?

Default parameters for wp_enqueue_script will output the script in the wp_head function. Shortcodes typically execute later, when main content is being output. In that case, calling wp_localize_script in the Shortcode handler will have no effect, because the script has already been output. Setting the $in_footer parameter to true when enqueueing the script will delay script … Read more

How to return a foreach inside a shortcode

As I said in the comment you can use buffering like this function stock_agenda() { $days = json_decode(file_get_contents(‘json_file’)); unset($days[0]); ob_start(); // start buffer ?> <table class=”table”> <thead> <tr> <th> Title </th> <th>Content</th> <th>Date</th> </tr> </thead> <tbody> <?php foreach($days as $day) { ?> <tr> <td><?php echo $day[0]; ?></td> <td><?php echo $day[1]; ?></td> <td><?php echo $day[2]; ?></td> … Read more