arrow_back
Back

WordPress shortcodes: add_shortcode, attributes, and nested content

Andrew Dorokhov Andrew Dorokhov schedule 1 min read

Add a shortcode:

/**
 * Add a shortcode.
 */
add_shortcode('chair-picker-tool', [ self::class, 'shortcode' ]);

Callback:

/**
 * Shortcode.
 *
 * @return string
 */
public static function shortcode() {

    return "<p>Test</p>";
}

Good practice to include files:

/**
 * Shortcode for the form.
 *
 * @return string
 */
public function shortcode_show_form()
{
    ob_start();

    require plugin_dir_path( __FILE__ ) . 'partials/shortcode-display.php';

    return ob_get_clean();
}
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

WordPress media library: attachments, uploads, and wp.media

arrow_forward