Php string not working in Wordpress Functions.php

How to pass the following code.

div ?php $category = get_the_category(); ?
      a  href=?php echo get_category_link($category[0]-cat_ID); ? 
      ?php echo $category[0]-cat_name; ? /a
/div

In the function.php file's following code.

$related_blog .=//want to pass the above code here.;

For detailed description visit here: click here

Topic link-category functions php categories Wordpress

Category Web


You can use below code to append the string:

<?php
$category = get_the_category();
$related_blog .= '<div><a  href="'. get_category_link($category[0]->cat_ID). '">'. $category[0]->cat_name.' </a></div>';
?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.