如何从页面的代码编辑器访问主题模板变量?

时间:2021-03-19 20:29:21

标签: php wordpress wordpress-theming

我为我的页面创建了一个新的 php 模板,并使用页面属性 - 模板来选择它。这个 php 模板有一个 $imageData 变量,我想用代码编辑器(而不是 echo)将它加载到我的页面中

这是我的 PHP 文件的一部分(其余部分是从 single.php 复制的)

$variWanted ="meme";
$image = 'https://google.com/'.$variWanted.';
$imageData = base64_encode(file_get_contents($image));
echo '<img src="data:image/jpeg;base64,'.$imageData.'" alt=“image description” title=“image tooltip”>';

当我进入我的页面并点击代码编辑器时,我希望 img src 加载 $imageData 而不是 image-5.jpg 链接

<!-- wp:gallery {"ids":[4,5,6,7,8],"linkTo":"none","align":"full"} -->
<figure class="wp-block-gallery alignfull columns-3 is-cropped"><ul class="blocks-gallery-grid"><li 
class="blocks-gallery-item"><figure>
<img src="https://mywebsite/wp-content/uploads/2021/03/image-5.jpg" alt="Image description" data-d="4" class="wp-image-4"/></figure></li><li class="blocks-gallery-item"><figure>

0 个答案:

没有答案