- get_theme_file_path() │ WP 4.7.0
- Возвращает
- Использование
- Примеры
- #1 Демо
- #2 Подключение файла из каталога темы inc
- #3 Подключим файл темы учитывая дочернюю тему.
- Список изменений
- Код get_theme_file_path() get theme file path WP 6.2.2
- Cвязанные функции
- theme path url (папка темы)
- Подключение файлов темы
- Get Theme Directory In WordPress
- get_template_directory_uri()
- get_stylesheet_directory_uri()
- get_stylesheet_uri()
- get_theme_root_uri()
- get_theme_root()
- get_theme_roots()
- get_stylesheet_directory()
- get_template_directory()
- Php cd path to theme dir
- Theme path to plugin path
- Drupal: Path to inline image <img> inside page.tpl.php
- Get_template_directory() still returning path to previous theme
- In the Los Angeles area?
- We also take mail orders.
get_theme_file_path() │ WP 4.7.0
Получает путь до указанного файла темы. Учитывает дочерние темы. Функция пытается найти указанный файл сначала в дочерней теме, если его там нет, то получает путь до файла из основной темы. Функция создана, для того, чтобы повсеместно использоваться при создании тем, чтобы все пути в теме поддерживали дочерние темы. С появлением этой функции не нужно вручную писать проверки с использованием get_template_directory_uri() и get_template_directory().
Хуки из функции
Возвращает
Использование
$file(строка) Название файла который нужно найти в теме. Например file.php . Можно указать вложенный файл inc/file.php или так /inc/file.php . Если оставить строку пустой, то вернет путь до активной темы. См. get_stylesheet_directory() По умолчанию: »
Примеры
#1 Демо
echo get_theme_file_path( 'myfile.php' ); /* В результате получим путь к одному из файлов: /home/site/www/wp-content/themes/wpkama-child/myfile.php или /home/site/www/wp-content/themes/wpkama/myfile.php */
#2 Подключение файла из каталога темы inc
include get_theme_file_path( '/inc/template.php' );
#3 Подключим файл темы учитывая дочернюю тему.
require_once( get_theme_file_path( 'myfile.php' ) );
В результате функция проверит если ли файл myfile.php в дочерней теме, если его нет, то подключит его из основной темы. Добавить свой пример
Список изменений
Код get_theme_file_path() get theme file path WP 6.2.2
function get_theme_file_path( $file = '' ) < $file = ltrim( $file, '/' ); if ( empty( $file ) ) < $path = get_stylesheet_directory(); >elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) < $path = get_stylesheet_directory() . '/' . $file; >else < $path = get_template_directory() . '/' . $file; >/** * Filters the path to a file in the theme. * * @since 4.7.0 * * @param string $path The file path. * @param string $file The requested file to search for. */ return apply_filters( 'theme_file_path', $path, $file ); >
Cвязанные функции
theme path url (папка темы)
Подключение файлов темы
Get Theme Directory In WordPress
When you doing theme development there are times when you need to reference a file in the same folder of the current theme. You may need to include a file in your code or add a stylesheet to your website. There are many different ways you can include a file in your code, WordPress comes with a number of constants that you can use in your development to get paths to your wp-content folder or plugin folders.
WP_CONTENT_DIR // no trailing slash, full paths only WP_CONTENT_URL // full url WP_PLUGIN_DIR // full path, no trailing slash WP_PLUGIN_URL // full url, no trailing slash
These are hardcoded constants so if you want to reference a specific theme you will need to hardcode the theme name in your code.
$twentyThirteenTheme = WP_CONTENT_DIR . '/themes/twentythirteen/'; $twentyThirteenThemeStylesheet = WP_CONTENT_URL . '/themes/twentythirteen/style.css';
The problem you have with this is that if your theme name changes then it will break your code. WordPress comes with a number of useful functions you can use to get the current theme path or URL.
get_template_directory_uri() get_stylesheet_directory_uri() get_stylesheet_uri() get_theme_root_uri() get_theme_root() get_theme_roots() get_stylesheet_directory() get_template_directory()
get_template_directory_uri()
This function will return the URL of the current theme, it will not return a trailing slash. If you are using a child theme then this function will return the parent theme directory URL.
Use this function to include a new Stylesheet or Javascript file in your theme.
add_action('wp_enqueue_scripts', 'my_scripts_method'); ?>
get_stylesheet_directory_uri()
This function will return the URL for the current theme, if you are running a child theme then this will return the child theme directory URL.
This can be used exactly the same way as the get_template_directory_uri().
add_action('wp_enqueue_scripts', 'my_scripts_method'); ?>
get_stylesheet_uri()
The above functions will return the URL for the directory of the current theme, this function will return the URL of the current theme stylesheet URL. If you are using the child theme then this will return the child theme stylesheet URL.
get_theme_root_uri()
THis function will return the URL to the theme directory.
get_theme_root()
This function will return the file path of the themes directory without a trailing slash.
get_theme_roots()
Return an array of themes located in the themes directory.
get_stylesheet_directory()
This function will return the the full file path to the current theme directory, like the get_stylesheet_directory_uri() this will return the current theme even if it’s being used as the child theme.
Use this function to include files in your application from the current theme.
get_template_directory()
This function will return the full file path to the current theme directory, like the get_template_directory_uri() if you are using a child theme then this function will return the path to the parent theme directory.
Use this function to include files in your application from the current theme.
Php cd path to theme dir
Question: If I throw the above file in some plugin then what will be the path name? let’s say the name of the plugin is Solution: To require from current plugin use constant: To require file from other plugin or theme use constant: Question: In WordPress, I’ve been installing and using various themes, including 2013, Roots, and now BlankSlate. Solution 1: Use: Instead of: Solution 2: first of all you can check both theme name is different goto current theme, index page and change template name Question: I am just tried to create a module name and tried to apply theme to that module in drupal6.
Theme path to plugin path
require_once(get_template_directory().'/inc/MCAPI.class.php');
If I throw the above file in some plugin then what will be the path name?
let’s say the name of the plugin is pluginzigsaw
To require from current plugin use __DIR__ constant:
require_once(__DIR__ . ‘/inc/MCAPI.class.php’);
To require file from other plugin or theme use WP_PLUGIN_DIR constant: require_once(WP_PLUGIN_DIR . ‘/plugin_name/inc/MCAPI.class.php’);
WordPress — How to set child theme path, I am trying to set the child theme path. Instead of having child theme templates loaded from the standard location I want to load them from a different location. For example I have themes: wp-con
Drupal: Path to inline image <img> inside page.tpl.php
Drupal: Path to inline image <img> inside page.tpl. php to theme /images/ dir ?Helpful? Please support me on Patreon: https:
Get_template_directory() still returning path to previous theme
In WordPress, I’ve been installing and using various themes, including 2013, Roots, and now BlankSlate. I noticed that now that I’ve activated BlankSlate, the function get_template_directory() used in front-page.php is still returning the path to the Roots theme directory. My current front-page.php looks like this.
In the Los Angeles area?
Ask about free demo loaners!
We also take mail orders.
On all orders, there is a 30-day return policy!
Источник