/wordpress_101

Useful WordPress functions, actions, hooks, wp-cli commands

Primary LanguagePHP

Useful and frequently used WordPress functions.

WP-Cli Commands

Get wp-cli version

wp --info

Update all the themes

wp theme update --all

Create a new plugin

Navigate to wp-content/plugins/. Then run this command to create a new plugin called my-awesome-plugin.

wp scaffold plugin my-awesome-plugin

create_a_wordpress_plugin_with_wpcli

Update all the plugins

wp plugin update --all

Cron job & Transient API

Check this example code.

Function comment style

/**
 * List of views served by this composer.
 *
 * @var array
 * @return array
 */

Shortcode Class example

class My_Shortcode{
  public function __construct(){
    $this->register_shortcode();
  }

  public function register_shortcode(){
    add_shortcode('shortcode_tag', [$this, 'get_shortcode_output']);
  }

  public function get_shortcode_output($atts){
    return "Hello world"
  }
}

// Initalize the class.

new My_Shortcode();