Home>

I want to replace the class to be displayed at the specified time in the WordPress template file (front-page.php).
Since there are multiple lines of html, I thought I would use a here document, but the html I write in the here document contains an image, and the path to the image is output with the get template directory uri of the WordPress template tag. I will.
After a lot of research, I found that the function cannot be used as it is in the here document, but since PHP has almost no knowledge for building WordPress, how to describe it will expand the function correctly. I don't know if it is. .. ..
The following is the source I am currently writing. For the time being, the template tag is described in the same way as when it is described outside the here document. .. .. I would be grateful if you could teach me.

<? php
date_default_timezone_set ("Asia/Tokyo");
if (strtotime (date ('Y-m-d H: i'))<strtotime ('2020-12-25 10:00'))
{
echo<<<EOF


// I want to expand get template directory uri below.
/Path to image">
facebook


EOF;
} else {
echo<<<EOF


// I want to expand get template directory uri below.
/Path to image">
facebook


EOF;
}
?>
  • Answer # 1

    It would be better to receive the execution result of the function as a variable once outside the here document and expand only the variable to the here document.
    The fact that it can be output with echo means that the execution result of the function is a character string, so there is no problem even if it is received by a variable.

    Example

    $hoge = hogeFunc ();
    echo<<<DOC
    aaa<br>
    ${hoge}<br>
    bbb
    DOC;