无法让php在短代码内容内工作

无法让php在短代码内容内工作,php,wordpress,shortcode,Php,Wordpress,Shortcode,我尝试了几种解决方案,从网站内的类似问题看,但它不会工作我=(请帮忙 这是我原始代码的摘录: <form action="" method="get"> <input type="text" name="search" value=""> <input type="submit" value="Search"> <?php echo do_shortcode('[expand] <input type="checkbox" name="title"

我尝试了几种解决方案,从网站内的类似问题看,但它不会工作我=(请帮忙

这是我原始代码的摘录:

<form action="" method="get">
<input type="text" name="search" value="">
<input type="submit" value="Search">
<?php echo do_shortcode('[expand]
<input type="checkbox" name="title" <?php if(isset($_GET['title'])) echo "checked='checked'"; ?>>
    <label for="ti">Title</label></td>
[/expand]'); ?>
</form>


不,不能。字符串中的php代码不是php代码。您必须检测实际上是php的部分,并对其进行评估

在将字符串传递给
do\u shortcode()
函数之前,创建要嵌入
[expand]
标记中的字符串。

而不是> 标题 [/expand]');?>

干脆

<?php
$state = isset($_GET['title'])?"checked='checked'":"";
$expand = "[expand]
<input type=\"checkbox\" name=\"title\" ".$state. " >";
echo do_shortcode($expand);?>
您可以试试这个

<form action="" method="GET">
    <input type="text" name="search" value="">
    <input type="submit" value="Search">
    <?php 
     $check=isset($_GET['title']) ? "checked='checked'" : '';
     echo do_shortcode('[expand]
     <input type="checkbox" name="title" '.$check.' ><label for="ti">Title</label></td>
     <input type="submit" value="Search">
     [/expand]'); 
    ?>
</form>

你需要开门吗