I want to create a shortcode for my WordPress website so that I can add my random quotes most anywhere on the site. I will explain how I add all the shortcode options and actually perform the search for the random code in later posts. This post will show how to create a basic shortcode.

I can add the following code to my theme’s function.php file:


//[random-quote]
function random_quote_func( $atts ){

	return 'This is my famous quote';
}
add_shortcode( 'random-quote', 'random_quote_func' );

Adding the following shortcode to a WordPress post or page editor:

[[random-quotes]]

Produces the following results:

[random-quotes]

1 thought on “Creating a WordPress Shortcode”

  1. Pingback: How to Choose a Random Post with a Custom Post Type in a Wordpress Shortcode - Cullen Web Services

Leave a Comment

Your email address will not be published. Required fields are marked *