Answer the question
In order to leave comments, you need to log in
How to remove circular category links in WordPress in PHP?
I need to remove the circular links (links that lead to themselves) of the headings on the main page. The site is powered by WordPress. The structure is such that on the main page, next to each post, there is its heading (link). When a person clicks on a post heading, all posts of that heading are displayed. And next to each post there are also these rubric links. I need to make them non-links so that only their title is displayed.
Categories are displayed using the <?php the_category(); ?>. In the HTML source code, no class is added to them.
Tried to do like this:
<?php $cat = get_the_category();?>
<?php if (is_category($cat)) : ?>
<?php single_cat_title()?>
<?php else : ?>
<?php the_category(); ?>
<?php endif; ?>
Answer the question
In order to leave comments, you need to log in
Just digging there. It is necessary to look for the output of the link (<a href), and put a condition for checking the value of the link with $_SERVER["REQUEST_URI"] on it, for example (depending on whether absolute or relative links are generated). Look for the output of these links by some indirect factors (maybe they have a special class somewhere) by searching through Notepad++'s files. Then determine if the displayed url does NOT match the one we went to the current page, then everything goes on as usual, if it matches - display span instead of href.
I'm on my phone so I can't elaborate, sorry.
*********************
It is necessary to find out how the link to the category is displayed.
Then check something like this:
$current_url = (is_ssl()?'https://':'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$item_url = esc_attr( $item->url ); //здесь нам надо переменной $item_url передать значение из переменной, которая участвует в выводе самой ссылки в шаблон
//потом проверка
if ( $item_url != $current_url ){ //если выводимая ссылка не равна текущей странице
оператор вывода html кода;
} else { //иначе, если совпадает
оператор вывода кода для циклической ссылки;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question