Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created January 4, 2017 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellofromtonya/ced966dd791820c50aa8010dd582d222 to your computer and use it in GitHub Desktop.
Save hellofromtonya/ced966dd791820c50aa8010dd582d222 to your computer and use it in GitHub Desktop.
add_shortcode example
add_shortcode( 'faq', 'process_the_faq_shortcode' );
/**
* Process the FAQ Shortcode to build a list of FAQs.
*
* @since 1.0.0
*
* @param array|string $user_defined_attributes User defined attributes for this shortcode instance
* @param string|null $content Content between the opening and closing shortcode elements
* @param string $shortcode_name Name of the shortcode
*
* @return string
*/
function process_the_faq_shortcode( $user_defined_attributes, $content, $shortcode_name ) {
$attributes = shortcode_atts(
array(
'number_of_faqs' => 10,
'class' => '',
),
$user_defined_attributes,
$shortcode_name
);
// do the processing
// Call the view file, capture it into the output buffer, and then return it.
ob_start();
include( __DIR__ . '/views/faq-shortcode.php' );
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment