Skip to content

Instantly share code, notes, and snippets.

@dcangulo
Last active April 3, 2018 06:20
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 dcangulo/4599c59975c782ea771b8548fadf63b1 to your computer and use it in GitHub Desktop.
Save dcangulo/4599c59975c782ea771b8548fadf63b1 to your computer and use it in GitHub Desktop.
A WordPress plugin shortcode template on both oop and procedural approach. Visit https://www.davidangulo.xyz/ for more information.
<?php
/*
Plugin Name: Example Shortcode Plugin
Plugin URI: https://wordpress.org/plugins/
Description: Just another example shortcode plugin.
Version: 1.0.0
Author: David Angulo
Author URI: https://www.davidangulo.xyz/
*/
class myShortCode {
public function __construct() {
add_shortcode("my_custom_shortcode",array($this,"myShortCodeRender"));
}
public function myShortCodeContent() {
echo "Hello! I am a custom shortcode.";
}
public function myShortCodeRender() {
ob_start();
$this->myShortCodeContent();
return ob_get_clean();
}
}
$object = new myShortCode;
//Visit the tutorial for more information
//https://www.davidangulo.xyz/website-development/how-to-create-custom-wordpress-shortcode-plugin-from-scratch/
<?php
/*
Plugin Name: Example Shortcode Plugin
Plugin URI: https://wordpress.org/plugins/
Description: Just another example shortcode plugin.
Version: 1.0.0
Author: David Angulo
Author URI: https://www.davidangulo.xyz/
*/
function myShortCodeContent() {
echo "Hello! I am a custom shortcode.";
}
function myShortCodeRender() {
ob_start();
myShortCodeContent();
return ob_get_clean();
}
add_shortcode("my_custom_shortcode","myShortCodeRender");
//Visit the tutorial for more information
//https://www.davidangulo.xyz/website-development/how-to-create-custom-wordpress-shortcode-plugin-from-scratch/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment