WordPress как на ладони
rgbcode is looking for WordPress developers. Очень Удобный и Быстрый Хостинг для сайтов на WordPress. Пользуюсь сам и вам рекомендую!

get_bloginfo()WP 0.71

Получает информацию о сайте из настроек.

Это копия bloginfo(), только эта функция получает результат в переменную, а не выводит его на экран.

Основа для: bloginfo()
1 раз — 0.00019 сек (быстро) | 50000 раз — 6.07 сек (быстро)
Хуки из функции

Возвращает

Строку. Указанные данные.

Использование

get_bloginfo( $show, $filter );
$show(строка)
Имя параметра информацию о котором нужно получить
По умолчанию: name (название блога)
$filter(строка)
Название фильтра через который нужно прогонять выводимую информацию. Может быть: display или raw. Если указано display, то результат фильтруется через фильтр bloginfo.
По умолчанию: 'raw'

Примеры

0

#1 Поля которые можно указать в $show

Имена которые можно передать функции в параметре $show и то, что в итоге она выведет:

Опция Описание
name Называние сайта: Настройки > Основные
description Описание сайта: Настройки > Основные
wpurl УРЛ сайта (админки): Настройки > Основные. Данные берутся из опции "siteurl" wp_options. Псевдоним site_url().
url УРЛ сайта (фронта): Настройки > Основные. Данные берутся из опции "home" wp_options. Псевдоним home_url()
admin_email Email администратора: Настройки > Основные. Данные берутся из "admin_email" в таблице wp_options.
charset Кодировка блога. Данные берутся из "blog_charset" в таблице wp_options. С версии 3.5 кодировка блога не настраивается из админки и этот параметр всегда равен utf-8.
version Версия WP. Данные берутся из переменной $wp_version.
html_type Тип контента HTML страницы (по умолчанию: "text/html"). Данные берутся из "html_type" в таблице wp_options. Темы и плагины могут переписать эту переменную через хук pre_option_html_type.
language Язык сайта (локаль), например ru-RU.
stylesheet_url УРЛ на CSS стили сайта (обычно это файл style.css). Псевдоним get_stylesheet_uri().
stylesheet_directory УРЛ на директорию темы, где находится файл стилей. Псевдоним get_stylesheet_directory_uri().
template_directory
template_url
УРЛ на директорию темы. Псевдоним get_template_directory_uri().
pingback_url УРЛ файла пингов XML-RPC (xmlrpc.php).
atom_url УРЛ Atom фида (/feed/atom).
rdf_url УРЛ RDF/RSS 1.0 фида (/feed/rfd).
rss_url УРЛ RSS 0.92 фида (/feed/rss).
rss2_url УРЛ RSS 2.0 фида (/feed).
comments_atom_url УРЛ Atom фида комментариев (/comments/feed).
comments_rss2_url УРЛ RSS 2.0 фида комментариев (/comments/feed).
home Запрещена с версии 2.2. Используйте home_url().
siteurl Запрещена с версии 2.2. Используйте site_url().

Те же параметры со значениями:

admin_email           = admin@example.ru
atom_url              = http://example.ru/feed/atom
charset               = UTF-8
comments_atom_url     = http://example.ru/comments/feed/atom
comments_rss2_url     = http://example.ru/comments/feed
description           = Just another WordPress blog
html_type             = text/html
language              = en-US
name                  = Testpilot
pingback_url          = http://example.ru/xmlrpc.php
rdf_url               = http://example.ru/feed/rdf
rss2_url              = http://example.ru/feed
rss_url               = http://example.ru/feed/rss
stylesheet_directory  = http://example.ru/wp-content/themes/largo
stylesheet_url        = http://example.ru/wp-content/themes/largo/style.css
template_directory    = http://example.ru/wp-content/themes/largo
template_url          = http://example.ru/wp-content/themes/largo
text_direction        = ltr
url                   = http://example.ru
version               = 2.7
wpurl                 = http://example.ru

Дефолтное использование. Передадим название блога в переменную $blog_title, чтобы затем использовать переменную где-нибудь.

<?php $blog_title = get_bloginfo(); ?>
//используем переменную
<?php echo $blog_title ?>

Тоже самое будет возвращено функцией, если написать так:

<?php $blog_title = get_bloginfo('name'); ?>

Возможный пример использования функции в шаблоне WordPress:

<?php echo 'Короткое описание блога: ' . get_bloginfo('description', 'display');  ?><br />
//в результате на экране появится такая надпись: Короткое описание блога: <здесь описание>

Заметки

  • Global. Строка. $wp_version The WordPress version string.

Список изменений

С версии 0.71 Введена.

Код get_bloginfo() WP 6.4.3

function get_bloginfo( $show = '', $filter = 'raw' ) {
	switch ( $show ) {
		case 'home':    // Deprecated.
		case 'siteurl': // Deprecated.
			_deprecated_argument(
				__FUNCTION__,
				'2.2.0',
				sprintf(
					/* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument. */
					__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ),
					'<code>' . $show . '</code>',
					'<code>bloginfo()</code>',
					'<code>url</code>'
				)
			);
			// Intentional fall-through to be handled by the 'url' case.
		case 'url':
			$output = home_url();
			break;
		case 'wpurl':
			$output = site_url();
			break;
		case 'description':
			$output = get_option( 'blogdescription' );
			break;
		case 'rdf_url':
			$output = get_feed_link( 'rdf' );
			break;
		case 'rss_url':
			$output = get_feed_link( 'rss' );
			break;
		case 'rss2_url':
			$output = get_feed_link( 'rss2' );
			break;
		case 'atom_url':
			$output = get_feed_link( 'atom' );
			break;
		case 'comments_atom_url':
			$output = get_feed_link( 'comments_atom' );
			break;
		case 'comments_rss2_url':
			$output = get_feed_link( 'comments_rss2' );
			break;
		case 'pingback_url':
			$output = site_url( 'xmlrpc.php' );
			break;
		case 'stylesheet_url':
			$output = get_stylesheet_uri();
			break;
		case 'stylesheet_directory':
			$output = get_stylesheet_directory_uri();
			break;
		case 'template_directory':
		case 'template_url':
			$output = get_template_directory_uri();
			break;
		case 'admin_email':
			$output = get_option( 'admin_email' );
			break;
		case 'charset':
			$output = get_option( 'blog_charset' );
			if ( '' === $output ) {
				$output = 'UTF-8';
			}
			break;
		case 'html_type':
			$output = get_option( 'html_type' );
			break;
		case 'version':
			global $wp_version;
			$output = $wp_version;
			break;
		case 'language':
			/*
			 * translators: Translate this to the correct language tag for your locale,
			 * see https://www.w3.org/International/articles/language-tags/ for reference.
			 * Do not translate into your own language.
			 */
			$output = __( 'html_lang_attribute' );
			if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) {
				$output = determine_locale();
				$output = str_replace( '_', '-', $output );
			}
			break;
		case 'text_direction':
			_deprecated_argument(
				__FUNCTION__,
				'2.2.0',
				sprintf(
					/* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name. */
					__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ),
					'<code>' . $show . '</code>',
					'<code>bloginfo()</code>',
					'<code>is_rtl()</code>'
				)
			);
			if ( function_exists( 'is_rtl' ) ) {
				$output = is_rtl() ? 'rtl' : 'ltr';
			} else {
				$output = 'ltr';
			}
			break;
		case 'name':
		default:
			$output = get_option( 'blogname' );
			break;
	}

	$url = true;

	if ( ! str_contains( $show, 'url' )
		&& ! str_contains( $show, 'directory' )
		&& ! str_contains( $show, 'home' )
	) {
		$url = false;
	}

	if ( 'display' === $filter ) {
		if ( $url ) {
			/**
			 * Filters the URL returned by get_bloginfo().
			 *
			 * @since 2.0.5
			 *
			 * @param string $output The URL returned by bloginfo().
			 * @param string $show   Type of information requested.
			 */
			$output = apply_filters( 'bloginfo_url', $output, $show );
		} else {
			/**
			 * Filters the site information returned by get_bloginfo().
			 *
			 * @since 0.71
			 *
			 * @param mixed  $output The requested non-URL site information.
			 * @param string $show   Type of information requested.
			 */
			$output = apply_filters( 'bloginfo', $output, $show );
		}
	}

	return $output;
}
10 комментариев
    Войти