Hot to Link to category titles if it is in the single post content?

Question

Sorry my English is not good.

I want to link to titles of child-categories that are in the single post content?

<?php
$term_id = 1209;
$taxonomy_name = 'category';
$termchildren = get_term_children( $term_id, $taxonomy_name );
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
$mycatone = "'" . $term->name . "',";
$mycattwo = "'<a href='https://stackexchange.com'>" . $termd->name . "</a>',";
}
function link_words($content){
$words = array(
$mycatone 
);
$links = array(
$mycattwo 
);
$content = str_replace($words , $links ,$content);
return $content;
}
add_filter('the_content', 'link_words');
?>

<?php the_content() ?>
0
Ramin 2 years 2019-12-24T09:40:24-05:00 0 Answers 76 views 0

Leave an answer

Browse
Browse