Shortcodes Generator

Overview

Use this tool to create custom code for Shortcodes with add_shortcode() function.

Usage

  • Fill in the user-friendly form.
  • Click the “Update Code” button.
  • Copy the code to your project.
  • Or save it as a snippet and share with the community.
Shortcode tag in the content.
e.g. [tag]
The function used in the code.
Self-closing shortcode: [tag]
Enclosing shortcode: [tag]content[/tag]
Enable attributes such as
[tag foo="123" bar="456"].
Use "shortcode_atts_{$shortcode}" filter, to allow shortcode attributes filtering.
Set custom filter name.
Attribute name. Lowercase.
Default value.
e.g. [tag attr_name="default_value"]
Attribute name. Lowercase.
Default value.
Attribute name. Lowercase.
Default value.
Custom code to generate the output.
Should only "return" the text, never produce the output directly.
  Save Snippet
// Add Shortcode
function random_tests() {

	$args = array (
		'post_type'              => array( 'cw_tests' ),
		'post_status'            => array( 'publish' ),
		'nopaging'               => true,
		'posts_per_page'         => '10',
		'orderby'                => 'rand',
		);
	
		// The Query
	$query = new WP_Query( $args );
		//var_dump($query);
	
	if ( $query->have_posts() ) {
		while ( $query->have_posts() ) {
			$query->the_post();
			echo get_the_title();
		}
		/* Restore original Post Data */
		wp_reset_postdata();
	} else {
		// no posts found
		echo "NO HAY TEST ๐Ÿ™„";
	}

}
add_shortcode( 'test', 'random_tests' );