简体   繁体   中英

PHP inside HTML Comments/Tags

Okay so here is my head

<head>

<meta charset="utf-8">
<title><?php echo $title ?></title>
<meta name="description" content="<?php echo $metadescription ?>">
<meta name="author" content="Talk About Film">

</head>

and my pages

<?php 
$title ="Talk About Film | Trailers | <?php echo the_field('trailer_title'); ?>";
$metadescription= "Watch the latest trailer for <?php echo the_field('trailer_title'); ?>, watch the latest trailers at Talk About Film";
include 'includes/header.php' ?>

In the source however the PHP tags show not the content it pulls from the field. ie

 <title>Talk About Film | Trailers | <?php the_field('trailer_title'); ?></title>

Not sure if you can use PHP in this way, or if there is a simple fix?

You're already inside a <?php ?> block when you open another. Change it to this:

<?php 
$title ="Talk About Film | Trailers | ".the_field('trailer_title');
$metadescription= "Watch the latest trailer for ".the_field('trailer_title').", watch the latest trailers at Talk About Film";
include 'includes/header.php' ?>
<?php 
$title ="Talk About Film | Trailers | <?php echo the_field('trailer_title'); ?>";
$metadescription= "Watch the latest trailer for <?php echo the_field('trailer_title'); ?>, watch the latest trailers at Talk About Film";
include 'includes/header.php' ?>

should be

<?php 
$title ="Talk About Film | Trailers | " . the_field('trailer_title');
$metadescription= "Watch the latest trailer for " . the_field('trailer_title') . ", watch the latest trailers at Talk About Film";
include 'includes/header.php' ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM