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

Adding shortcode closing tag after a loop

Collect all of the loop’s output in a variable, wrap it in the accordion shortcode, then pass that through do_shortcode: $output=””; if ( have_posts() ) : while ( have_posts() ) : the_post(); $output .= ‘<div class=”col-lg-12 col-md-12 col-sm-12 col-xs-12″>’; $output .= do_shortcode(‘[su_spoiler title=”‘.get_the_title().'” open=”no” style=”default” icon=”plus” anchor=”” class=””]’.get_the_content().'[/su_spoiler]’); $output .= ‘</div>’; endwhile; else : $output … Read more

WP_Query is printing out only one post when posts_per_page is set to multiple

you are re-initializing the out variable that is why it shows only one product // Custom Post Type for Use Cases page slider function create_post_type() { register_post_type( ‘use_cases’, array( ‘labels’ => array( ‘name’ => __( ‘Use Cases’ ), ‘singular_name’ => __( ‘Use_Case’ ) ), ‘public’ => true, ‘has_archive’ => true, ) ); } add_action( ‘init’, … Read more