after_setup_theme
This is a WordPress - after_setup_theme hook. The plugin just uses it.
Fires on every page load immediately after the theme is initialized. It is normally used to set up basic theme features; see add_theme_support().
This is one of the earliest hooks. It fires immediately before WordPress initialization and before the init hook.
Unlike init, WordPress has not yet determined whether the user is logged in when this hook fires.
Usage
add_action( 'after_setup_theme', 'wp_kama_after_setup_theme_action' );
/**
* Function for `after_setup_theme` action-hook.
*
* @return void
*/
function wp_kama_after_setup_theme_action(){
// action...
}
Examples
#1 after_setup_theme usage in the default Twenty Twelve theme
This example shows how to use after_setup_theme to register theme features such as featured images, post formats, and a header image.
/** Tell WordPress to run twentytwelve_setup() on the 'after_setup_theme' hook. */
add_action( 'after_setup_theme', 'twentytwelve_setup' );
// Set default theme options and add support for WordPress features.
function twentytwelve_setup() {
// Support an editor stylesheet. Place editor-style.css in the theme directory.
add_editor_style();
// Support post formats.
add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );
// Support featured images.
add_theme_support( 'post-thumbnails' );
// Add post and comment RSS links to the head section.
add_theme_support( 'automatic-feed-links' );
// Make the theme available for translation.
// Translation files must be located in /languages/.
load_theme_textdomain( 'twentytwelve', get_template_directory() . '/languages' );
$locale = get_locale();
$locale_file = get_template_directory() . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
require_once( $locale_file );
// Support wp_nav_menu() navigation menus.
register_nav_menus( array(
'primary' => __( 'Primary Navigation', 'twentytwelve' ),
'Secondary' => __( 'Secondary Navigation', 'twentytwelve' ),
) );
// Support a custom background.
add_custom_background();
// Set and modify options in the theme's HEADER section.
if ( ! defined( 'HEADER_TEXTCOLOR' ) )
define( 'HEADER_TEXTCOLOR', '' );
// Specify a header image URL. %s is replaced with the theme directory URL.
if ( ! defined( 'HEADER_IMAGE' ) )
define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' );
// Custom header height and width. These can be changed with the theme hooks shown below.
define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentytwelve_header_image_width', 940 ) );
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentytwelve_header_image_height', 198 ) );
// Use the post thumbnail as the header image for pages and posts.
// Required dimensions: 940 pixels wide and 198 pixels high.
// Large images are reduced automatically; small images remain unchanged.
set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
// No text is needed inside the header image.
if ( ! defined( 'NO_HEADER_TEXT' ) )
define( 'NO_HEADER_TEXT', true );
// Allow header image styles to be changed from the admin area.
// add_custom_image_header( '', 'twentytwelve_admin_header_style' );
}Where the hook is called
In file: /php/wp-settings-cli.php
after_setup_theme
wp-cli/php/wp-settings-cli.php 430
do_action( 'after_setup_theme' );