fix agroexpert links
This commit is contained in:
30
filters/fix_agroexpert_links.php
Normal file
30
filters/fix_agroexpert_links.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function fix_agroexpert_links($content) {
|
||||||
|
$needle = 'https://agroexpert.press';
|
||||||
|
$position = 0;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Если не заканчивается на / и нет query/anchor
|
||||||
|
if (!str_ends_with($link, '/') && !str_contains($link, '?') && !str_contains($link, '#')) {
|
||||||
|
$link_fixed = $link . '/';
|
||||||
|
$content = substr_replace($content, $link_fixed, $pos, strlen($link));
|
||||||
|
$position = $pos + strlen($link_fixed); // Продвигаемся дальше
|
||||||
|
} else {
|
||||||
|
$position = $end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_filter('the_content', 'fix_agroexpert_links');
|
||||||
@@ -31,6 +31,8 @@ function redirect_non_admin_users() {
|
|||||||
add_action('admin_init', '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('ENPART', 740);
|
||||||
define('EN_PARTS', '746,741,742,743,744,745');
|
define('EN_PARTS', '746,741,742,743,744,745');
|
||||||
|
|||||||
@@ -43,8 +43,13 @@
|
|||||||
<div class="article-single__content">
|
<div class="article-single__content">
|
||||||
<?php
|
<?php
|
||||||
//$content = get_the_content();
|
//$content = get_the_content();
|
||||||
$content = apply_filters('the_content', get_the_content());
|
$post_id = get_the_ID();
|
||||||
echo replace_first_figure_in_content($content);
|
if ( $post_id == 26011 ) {
|
||||||
|
the_content();
|
||||||
|
} else {
|
||||||
|
$content = apply_filters('the_content', get_the_content());
|
||||||
|
echo replace_first_figure_in_content($content);
|
||||||
|
}
|
||||||
//the_content(); ?>
|
//the_content(); ?>
|
||||||
<div class="article-social">Подписывайтесь на нас в <a href="https://dzen.ru/agroexpert_press?favid=254170145" target="_blank">Дзен</a> и <a href="https://t.me/agroexpert_press" target="_blank">Telegram</a></div>
|
<div class="article-social">Подписывайтесь на нас в <a href="https://dzen.ru/agroexpert_press?favid=254170145" target="_blank">Дзен</a> и <a href="https://t.me/agroexpert_press" target="_blank">Telegram</a></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user