rename theme day
This commit is contained in:
@@ -4,21 +4,48 @@ function fix_agroexpert_links($content) {
|
||||
$needle = 'https://agroexpert.press';
|
||||
$position = 0;
|
||||
|
||||
$excluded_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.svg', '.webp', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.zip', '.rar', '.mp3', '.mp4'];
|
||||
|
||||
while (($pos = strpos($content, $needle, $position)) !== false) {
|
||||
// Найдём конец ссылки (до пробела, кавычки или закрывающего тега)
|
||||
$end = $pos + strlen($needle);
|
||||
while (isset($content[$end]) && !in_array($content[$end], ['"', "'", ' ', "\n", "\r", '<', '>'])) {
|
||||
$end++;
|
||||
}
|
||||
|
||||
// Вырежем саму ссылку
|
||||
$link = substr($content, $pos, $end - $pos);
|
||||
$lower_link = strtolower($link);
|
||||
|
||||
// Если не заканчивается на / и нет query/anchor
|
||||
if (!str_ends_with($link, '/') && !str_contains($link, '?') && !str_contains($link, '#')) {
|
||||
$link_fixed = $link . '/';
|
||||
// Проверка на параметры или якорь
|
||||
$has_query_or_anchor = str_contains($link, '?') || str_contains($link, '#');
|
||||
|
||||
// Получаем URL без параметров и якоря
|
||||
$link_base = strtok($link, '?#');
|
||||
|
||||
// Исключаем медиафайлы по расширению
|
||||
foreach ($excluded_extensions as $ext) {
|
||||
if (str_ends_with($link_base, $ext)) {
|
||||
$position = $end;
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Если есть ? и перед ним нет / — вставляем / перед ?
|
||||
if (str_contains($link, '?')) {
|
||||
$q_pos = strpos($link, '?');
|
||||
if ($q_pos > 0 && $link[$q_pos - 1] !== '/') {
|
||||
$link_fixed = substr($link, 0, $q_pos) . '/' . substr($link, $q_pos);
|
||||
$content = substr_replace($content, $link_fixed, $pos, strlen($link));
|
||||
$position = $pos + strlen($link_fixed); // Продвигаемся дальше
|
||||
$position = $pos + strlen($link_fixed);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Если нет / на конце базового пути и нет параметров/якоря — добавляем /
|
||||
if (!str_ends_with($link_base, '/')) {
|
||||
$suffix = substr($link, strlen($link_base)); // ?params или #anchor
|
||||
$link_fixed = $link_base . '/' . $suffix;
|
||||
$content = substr_replace($content, $link_fixed, $pos, strlen($link));
|
||||
$position = $pos + strlen($link_fixed);
|
||||
} else {
|
||||
$position = $end;
|
||||
}
|
||||
@@ -26,5 +53,3 @@ function fix_agroexpert_links($content) {
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
add_filter('the_content', 'fix_agroexpert_links');
|
||||
|
||||
@@ -30,10 +30,6 @@ function redirect_non_admin_users() {
|
||||
}
|
||||
add_action('admin_init', 'redirect_non_admin_users');
|
||||
|
||||
|
||||
require_once get_template_directory() . '/filters/fix_agroexpert_links.php';
|
||||
|
||||
|
||||
define('ENPART', 740);
|
||||
define('EN_PARTS', '746,741,742,743,744,745');
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ if ($pinned_post):
|
||||
$mainpost_id = $pinned_post->ID;
|
||||
?>
|
||||
|
||||
<div class="maintitle-mob">Главное</div>
|
||||
<div class="maintitle-mob">Тема дня</div>
|
||||
|
||||
<div class="article-item__text article-item-mob">
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ if ($pinned_post) :
|
||||
<div class="hero-banner__bg">
|
||||
<?=render_webp_picture_by_post( $pinned_post->ID );?>
|
||||
</div>
|
||||
<p class="hero-banner__main">Главное</p>
|
||||
<p class="hero-banner__main">Тема дня</p>
|
||||
<div class="hero-banner__content">
|
||||
<p class="hero-banner__title subtitle-16">
|
||||
<?php echo get_the_title($pinned_post->ID); ?>
|
||||
|
||||
Reference in New Issue
Block a user