Global Variables
Introduction
WordPress-specific global variables are used throughout WordPress code for various reasons. Almost all data that WordPress generates can be found in a global variable, which makes them very handy and important for developers.
To access a global variable in your code, you first need to globalize the variable with global $variable;
General Settings
- $wp_did_header (boolean) Whether WordPress has been instantiated yet
- $table_prefix (string) The MySQL table prefix for the WordPress install (default: 'wp_')
- $wp_version (string) The installed version of WordPress
- $wp_db_version (int) The version number of the database
- $tinymce_version (string) The installed version of TinyMCE
- $manifest_version (string) The cache manifest version
- $required_php_version (string) The version of PHP this install of WordPress requires
- $required_mysql_version (string) The version of MySQL this install of WordPress requires
- $blog_id (int) The ID of the blog. (Will be 1 unless Multisite is enabled)
- $PHP_SELF
- $timestart (float) PHP 4 standard microtime start capture.
- $wpdb The global instance of the Class_Reference/wpdb class.
- $_wp_using_ext_object_cache (boolean) If an object-cache.php file exists in the wp-content directory, it uses that drop-in as an external object cache.
- $wp_object_cache The global instance of the Class_Reference/WP_Object_Cache class.
- $wp_filter (array) A multi-dimensional array of all functions that have been added to filters/hooks.
- $merged_filters
- $wp_current_filter (array) Stores the list of current filters with the current one last.
- $allowedposttags (array) Stores HTML elements that are allowed in a post's content.
- $allowedtags (array) Stores HTML elements that are allowed in a post's title and comments.
- $allowedentitynames (array) Stores HTML entities that are allowed in a post.
- $current_site (NULL) Deprecated as of 3.2.1
- $current_blog (NULL) Deprecated as of 3.2.1
- $shortcode_tags (array) Stores a list of all registered shortcodes.
- $wp_embed The global instance of the WP_Embed class.
- $wp_registered_sidebars (array) Stores a multi-dimensional array of all registered sidebars and related details.
- $wp_registered_widgets (array) Stores a multi-dimensional array of all registered widgets and related details.
- $wp_registered_widget_controls (array) Stores the registered widget control options.
- $wp_registered_widget_updates private global.
- $_wp_sidebars_widgets private global.
- $_wp_deprecated_widgets_callbacks
- $wp_actions (array) Keeps a count of the number of times each action has been fired.
- $wp_default_secret_key
- $pagenow (string)
Browser Detection Booleans
These globals store data about which browser the user is on.
- $is_iphone (boolean) iPhone Safari
- $is_chrome (boolean) Google Chrome
- $is_safari (boolean) Safari
- $is_NS4 (boolean) Netscape 4
- $is_opera (boolean) Opera
- $is_macIE (boolean) Mac Internet Explorer
- $is_winIE (boolean) Windows Internet Explorer
- $is_gecko (boolean) FireFox
- $is_lynx (boolean)
- $is_IE (boolean) Internet Explorer
Web Server Detection Booleans
These globals store data about which web server WordPress is running on.
- $is_apache (boolean) Apache HTTP Server
- $is_IIS (boolean) Microsoft Internet Information Services (IIS)
- $is_iis7 (boolean) Microsoft Internet Information Services (IIS) v7.x
- $wp_rewrite
- $wp_taxonomies
- $wp
- $l10n
- $wp_post_types
- $_wp_post_type_features
- $wp_post_statuses
- $wp_theme_directories
- $path
- $comment_form_id
- $options
- $wp_the_query
- $wp_query
- $wp_widget_factory
- $locale
- $weekday
- $weekday_initial
- $weekday_abbrev
- $month
- $month_abbrev
- $wp_locale
- $content_width
- $_wp_theme_features
- $_wp_registered_nav_menus
- $_wp_additional_image_sizes
- $_wp_default_headers
Logged in User Data
These globals store information about the user logged into the site.
- $current_user (object) Returns an object with information about the user. Similar to the object returned by Function_Reference/get_userdata.
- $user_login (string) User's username.
- $userdata (object) Returns an object with information about the user. Similar to the object returned by Function_Reference/get_userdata.
- $user_level (string) User's numerical user level. See User_Levels.
- $user_ID (int) Numerical ID of the user.
- $user_email (string) User's email address.
- $user_url (string) User's website URL.
- $user_pass_md5 (string) User's password hashed by MD5.
- $user_identity (string) User's nickname.
- $pluginDomain
- $wpsmiliestrans
- $wp_smiliessearch
- $wp_admin_bar (object) Global instance of the WP_Admin_Bar class.
- $show_admin_bar (boolean) Returns true when the admin bar will be shown.
- $wp_styles (object) Global instance of the WP_Styles class. Stores information about registered stylesheets.
- $wp_scripts (object) Global instance of the WP_Scripts class. Stores information about registered javascripts.
- $wp_header_to_desc (array) A list of all HTTP Status Code Header Descriptions.
- $error
- $m
- $p
- $post_parent
- $subpost
- $subpost_id
- $attachment
- $attachment_id
- $name
- $static
- $pagename
- $page_id
- $second (int) 0-59
- $minute (int) 0-59
- $hour (int) 0-23
- $day (int) 1-31
- $monthnum (int) 1-12
- $year (int) 0-2011
- $w (int)
- $category_name
- $tag
- $cat
- $tag_id
- $author_name
- $feed
- $tb
- $paged (int) The page number used for pagination.
- $comments_popup
- $meta_key
- $meta_value
- $preview
- $s
- $sentence
- $fields
- $category__in
- $category__not_in
- $category__and
- $post__in
- $post__not_in
- $tag__in
- $tag__not_in
- $tag__and
- $tag_slug__in
- $tag_slug__and
- $ignore_sticky_posts
- $suppress_filters
- $cache_results
- $update_post_term_cache
- $update_post_meta_cache
- $post_type
- $posts_per_page
- $nopaging
- $comments_per_page
- $no_found_rows
- $order
- $query_string (string) Contains the entire query string separated from the URL.
- $posts (array) An array of all $post objects, including information on all posts compiled from the global $wp_query.
- $post (object) Returns an object with information about the last echoed post, as described in Function_Reference/get_post.
- $request (string) The SQL statement used to query for posts.
- $template (string) A local directory location of the theme template used.
- $wp_did_template_redirect
- $comment
- $wp_cockneyreplace
- $concatenate_scripts
- $compress_scripts
- $compress_css
Inside the Loop variables
While inside the loop, these globals are set, containing information about the current post being processed.
- $id (int) The ID of the content.
- $authordata (object) Returns an object with information about the author, set alongside the last $post. Object described in Function_Reference/get_userdata.
- $currentday Day of the post.
- $currentmonth Month of the post.
- $page (int) The page of the post, as specified by the query var page.
- $pages (int)The number of pages within a post, which are separated by elements.
- $multipage (boolean)Returns true if the post has multiple pages, related to $page and $pages.
- $more (boolean) Returns true if there are multiple pages in the post, related to $page and $pages.
- $numpages (int) Returns the number of pages in the post, related to $page and $pages.
- $wpcommentspopupfile
- $wpcommentsjavascript