WordPress

<a href=”https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/” target=_blank”>PHP Documentation Standards
JavaScript Documentation Standards

Files and Structure

wp-content
   themes
     {themename}
       index.php
       style.css

styles.css

/**
* Theme Name: My Theme Name
* Author: My Name
* Description: This is a great theme.
* Version: 1.1
*/

index.php

Objects

Custom Post Types

Custom Taxonomies

Custom Post Type Metabox

Theme Files

Doc ‘title’ tag

<title><?php
    global $page, $paged;
    wp_title( '|', true, 'right' );
    bloginfo( 'name' );
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) ){
        echo " | $site_description";
    }
    if ( $paged >= 2 || $page >= 2 ){
        echo ' | ' . sprintf( __( 'Page %s' ), max( $paged, $page ) );
    }
?></title>

H1 page title


Default value.

$ww_pageTitle = ''; if( is_404() ){ $ww_pageTitle = '404 Page Not Found'; } elseif( is_search() ){ if( get_search_query() == '' ){ $ww_pageTitle = 'Search Results for Everything'; } else { $ww_pageTitle = 'Search Results for: "' . get_search_query() . '"'; } } elseif( is_home() ){ $ww_pageTitle = get_bloginfo( 'name' ); } elseif( is_single() || is_page() ){ $ww_pageTitle = get_the_title(); } elseif( is_category() ){ $ww_pageTitle = single_cat_title("", false); } elseif( is_tag() ){ $ww_pageTitle = single_tag_title("", false); } elseif( is_day() ) { $ww_pageTitle = 'Daily Archive ' . get_the_date(); } elseif( is_month() ){ $ww_pageTitle = 'Monthly Archive ' . get_the_date('F Y'); } elseif( is_year() ){ $ww_pageTitle = 'Yearly Archive ' . get_the_date('Y'); } elseif( 'my_custom_post_tye_id' == get_post_type() ){ $ww_pageTitle = 'My Custom Post Type Name'; }

Display the site navigation menu

https://codex.wordpress.org/Function_Reference/wp_nav_menu

$args = array(
    'container' => 'false',
    'items_wrap' => '
    %3$s
', ); wp_nav_menu($args);

Display the date/time a post was published and updated

<p class="entry-meta">
    <span>Posted</span> <?php
        echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';
    ?>. <span>Last updated</span>
    <time datetime="<?php the_modified_time('Y-m-d'); ?>"><?php the_modified_time('F jS, Y'); ?></time>
</p>

Paging Navigation

<?php

if( is_single() )
{
    ?><div class="prev"><span>Prev</span><?php
        previous_post('%', '', 'yes');
    ?></div><div class="next"><span>Next</span><?php
        next_post('%', '', 'yes');
    ?></div><?php
}
else
{
    ?><div class="prev"><span>Prev</span><?php
        next_posts_link('Older Posts');
    ?></div><div class="next"><span>Next</span><?php
        previous_posts_link('Newer Posts');
    ?></div><?php;
}

?>

Post Thumbnails

// Thumbnail image.
<?php the_post_thumbnail(array(105,105));?>

// Thumbnail image and link.
<a class="post-image" href="<?php
    the_permalink();
?>"><?php
    the_post_thumbnail(array(105,105));
?></a>

Published and Last-Updated Times

<?php // Displays: Published 6 months ago. Last updated July 31st, 2015. ?>
Published <?php
    echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';
?>. Last updated <?php
    the_modified_time('F jS, Y');
?>.

<?php // Displays: Published July 31st, 2015. Last updated 5 days ago. ?>
Published <?php
    echo get_the_time('F jS, Y');
?>. Last updated <?php
    echo human_time_diff(get_the_modified_time('U'), current_time('timestamp'));
?> ago.

functions.php

Add post-type supports

add_action('init', 'ww_custom_init');
function ww_custom_init()
{    
    // Add excerpts on 'page' type posts.
    // Add the 'Excerpt' admin UI on the 'Edit Page' page.
    add_post_type_support( 'page', 'excerpt' );
}

Theme Setup and Support

/**
 * Theme Setup
 */

if ( ! function_exists( 'oce_theme_setup' ) )
{
    function oce_theme_setup()
    {
        // Add the 'Edit Menus' admin page under 'appearance -> menues'.
        add_theme_support( 'menus' );
    
        // Add the ability to attach thumbnails to posts.
        // Add the 'Featured Image' admin UI on the 'Edit Post' page.
        add_theme_support('post-thumbnails');
    
        // Display HTML5 markup for search forms.
        add_theme_support( 'html5', array( 'search-form' ) );

        /*
         * Switch default core markup to output valid HTML5.
         */
        add_theme_support( 'html5', array(
           'search-form',
           'comment-form',
           'comment-list',
           'gallery',
           'caption',
        ) );
        
        /*
        * Enable support for Post Formats.
        * @link https://codex.wordpress.org/Post_Formats
        */
        add_theme_support( 'post-formats', array(
           'aside',     // A short piece of content, typically styled without a title.
           'image',     // A single image.
           'video',     // A single video.
           'quote',     // A single quotation.
           'link',      // A single link to another site.
           'gallery',   // A gallery of images.
           'status',
           'audio',     // A single audio file.
           'chat',
        ) );
        
    } // oce_theme_setup
}
add_action( 'after_setup_theme', 'oce_theme_setup' );

WP Generated Head Markup

Remove the WordPress version meta tag

/**
 * Remove the WordPress version meta tag as a layer of security.
 * Removes: 
 */
remove_action( 'wp_head', 'wp_generator' );

Remove RSD

/**
 * RSD or “Real Simple Discovery” is the discovery mechanism used by XML-RPC clients.
 * If don’t use services like Flickr and Quora with your WordPress site, it’s a good idea to remove it.
 * 
 * Removes: 
 */
remove_action('wp_head', 'rsd_link');

Remove RSS from the Head

/**
 * Visitors don’t see any RSS content in .
 *
 * Where a RSS link points to RSS feed for comments published on the post. Comment subscribers
 * will get notified of new comments whether or not a RSS link is contained in the post.
 *
 * Indexing “comment RSS feeds” is not good for SEO, and attracts spambots.
 * Comment subscribers will get notified of new comments whether or not a RSS link is contained in the post.
 *
 * Also a good idea to “noindex” comments in robots.txt, except for the main RSS feeds for the site.
 *
 * Removes:
 * 
 */
remove_action('wp_head', 'feed_links_extra', 3);

Remove tagging support for Windows Live Writer

/**
 * The link points to a file called wlwmanifest.xml which is the resource file needed to enable
 * tagging support for Windows Live Writer.
 *
 * Removes:
 * 
 */
remove_action('wp_head', 'wlwmanifest_link');

Remove the canonical link

/**
 * Remove the 'canonical' link.
 * Removes: 
 */
remove_action('wp_head', 'rel_canonical');

Remove Shortlinks

/**
 * Shortlinks for posts in the head content are useless and may lead to
 * duplicate URL indexing (unlikely but not impossible).
 *
 * Removes: 
 */
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);

Remove emoji support

/**
 * Remove the core emoji support (just more useless javascript and styles) unless you of course need emoji.
 * Removes: _wpemojiSettings
 */
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );

Remove WP API footer link to wp-json

/**
 * Remove the WP API footer link to wp-json
 * Removes: 
 */
if( ! function_exists( 'oce_remove_wp_embed_js' ) )
{
    function oce_remove_wp_embed_js() {
        wp_deregister_script('wp-embed');
    }
}
add_action('wp_enqueue_scripts', 'oce_remove_wp_embed_js');

WP Generated Markup

Remove ‘width’ and ‘height’ attributes from ‘img’ tags

function remove_thumbnail_dimensions( $html ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );

Image Figure Support

Check out figure inserter: https://gist.github.com/rezen/3388415

Clean up the CSS classes in menus

// Remove extraneous classes from nav menus.
add_filter( 'nav_menu_css_class', 'ww_nav_classes' );
add_filter( 'nav_menu_item_id', 'ww_nav_classes' );
add_filter( 'page_css_class', 'ww_nav_classes' );
function ww_nav_classes( $var )
{
    if( is_array( $var ) )
    {
        return array_intersect(
            $var,
            array( // List of useful classes to keep
                'current_page_item',
                'current_page_parent',
                'current_page_ancestor'
            )
        );
    }
    else
    {
        return '';
    }
}

// Replace the css class string 'current_page_*' with 'active' in nav menus.
add_filter( 'wp_nav_menu','my_page_classes' );
function my_page_classes( $text )
{
    $replace = array( // List of classes to replace with "active"
        'current_page_item' => 'active',
        'current_page_parent' => 'active',
        'current_page_ancestor' => 'active',
    );
    return str_replace( array_keys( $replace ), $replace, $text );
}

The Excerpt

Append a custom ‘excerpt more’ link to all excerpts.

// Remove the default 'excerpt more' output.
add_filter( 'excerpt_more', 'ww_excerpt_more' );
function ww_excerpt_more( $exerptMoreMarkup ){ return ''; }

// Append a custom 'excerpt more' to the excerpt output.
add_filter('the_excerpt', 'ww_the_excerpt'); 
function ww_the_excerpt( $exerptMarkup ){
    return  $exerptMarkup . '' . __('Read Full Post', 'my-theme') . '';
}

Or, if you simply want to adjust the ‘more excerpt’ output when it is used.

// If "excerpt more" is used, replace it.
add_filter( 'excerpt_more', 'ww_excerpt_more' );
function ww_excerpt_more( $exerptMoreMarkup )
{
    return '' . __('More', 'my-theme') . '';
}

WP Admin

Remove the Admin Toolbar from the front-end

/**
 * Remove the Admin Toolbar from the front-end.
 */
add_filter( 'show_admin_bar', '__return_false' );

/**
 * Remove the Admin Toolbar from the front-end for non-admin users.
 */
if (!current_user_can('manage_options'))
{
    add_filter('show_admin_bar', '__return_false');
}

Remove the Theme and Plugins Editor

/**
 * Remove the Theme and Plugins Editor.
 * This theme does not allow users to play with the core theme or plugins files.
 */
define( 'DISALLOW_FILE_EDIT', true );

Remove the Customizer from the Admin

/**
 * Remove the Customizer.
 * All code below prevents access or hides the WordPress Customizer ( Front-end Editor ) Needed? see,
 * https://codex.wordpress.org/Theme_Customization_API
 */
function shmoo_customize() {
    // Disallow acces to an empty editor
    wp_die( sprintf( __( 'No WordPress Theme Customizer support - If needed check your functions.php' ) ) . sprintf( '
Go back' ) ); } add_action( 'load-customize.php', 'shmoo_customize' ); // Remove 'Customize' from Admin menu function remove_submenus() { global $submenu; unset($submenu['themes.php'][6]); // Customize // Appearance Menu } add_action('admin_menu', 'remove_submenus'); // Remove 'Customize' from the Toolbar -front-end function remove_admin_bar_links() { global $wp_admin_bar; $wp_admin_bar->remove_menu('customize'); } add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' ); // Add Custom CSS to Back-end head function shmoo_admin_css() { echo ''; } add_action('admin_head', 'shmoo_admin_css'); /** * Add Custom CSS to Remove the Customize link from the "Themes" page. */ function oce_remove_customize_current_theme_menu() { echo ''; } add_action('admin_head', 'oce_remove_customize_current_theme_menu');

Remove Admin Panel Menu Items

/**
 * Remove Admin Panel Menu Items.
 */
function my_remove_admin_menu_items()
{
    global $submenu;
    
    remove_menu_page('index.php');                  // Remove the 'Dashboard' menu item.
    remove_menu_page('edit.php');                   // Remove the 'Posts' menu item.
    remove_menu_page('upload.php');                 // Remove the 'Media' menu item.
    remove_menu_page('edit.php?post_type=page');    // Remove the 'Pages' menu item.
    remove_menu_page('edit-comments.php');          // Remove the 'Comments' menu item.
    remove_menu_page('themes.php');                 // Remove the 'Appearance' menu item.
        unset($submenu['themes.php'][6]);           // Remove the 'Appearance > Customizer' menu item.
    remove_menu_page('plugins.php');                // Remove the 'Plugins' menu item.
    remove_menu_page('users.php');                  // Remove the 'Users' menu item.
    remove_menu_page('tools.php');                  // Tools menu.
    remove_menu_page('options-general.php');        // Remove the 'Settings' menu item.
    remove_menu_page('edit.php?post_type=oce');     // Remove the 'Courses' ('oce' custom post-type) menu item.
}
add_action( 'admin_menu', 'my_remove_admin_menu_items', 999 );

Helpful Resources

Writing a Plugin
Plugin Handbook
<a href=”https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/” target=_blank”>PHP Documentation Standards
JavaScript Documentation Standards

Files and Structure

wp-content
   plugins
     {mypluginsname}
       my_plugin.php

my_plugin.php

Only the my_plugin.php file needs to be present for the plugin to work. The file must begin with at least this header:

<?php
/**
* Plugin Name: Handbook Example
*/

A slightly more robust header might look like this:

<?php

/**
* Plugin Name: My Plugin Name
* Author: My Name
* Description: This is my plugin.
* Version: 1.0
*/

Hooks

Activation / Deactivation Hooks

https://developer.wordpress.org/plugins/the-basics/activation-deactivation-hooks/

/*
 * This file: wp-content/plugins/my_plugin/my_plugin.php
 */

require_once( '/my_plugin_class_file.php' );

// Call the 'register_activation_hook' before instantiating the plugin class.
register_activation_hook( FILE, array ( 'My_Plugin_Class_Name', 'my_register_activation_hook_method_name') );

// Instantiate the plugin class.
$my_plugin = new My_Plugin_Class_Name();
/*
 * This file: wp-content/plugins/my_plugin/my_plugin_class_file.php
 */

class My_Plugin_Class_Name
{
    public function __construct()
    {
// Constructor plugin hooks go here. }
public function register_activation_hook()
{
    // Plugin activation hooks go here. 
}

}