Php string not working in WordPress Functions.php

Question

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

in progress 0
rt5277 2 weeks 2021-05-28T07:19:56-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-05-30T08:30:30-05:00

    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>';
    ?>
    

Leave an answer

Browse
Browse