-3

It's a php file on wordpress. And I'd like to know if I can put <?php> inside <p>, <h> or something similar so I can add css on specific id.

For example

 <div class="eight columns">
            <div class="padding-right">
                <p id="address"><?php the_candidate_address(); ?></p>

            </div>
</div>

Thanks!

POBOX
  • 31
  • 1
  • 4
  • 3
    sure you can. Just make sure you've PHP running and is `.php` extension. What's wrong with what you posted? – Funk Forty Niner Jul 30 '16 at 18:15
  • 3
    You can write PHP code everywhere you want in any .php file. Why didn't you simply test your example? You could even write `

    attribute="data">`.

    – Pinke Helga Jul 30 '16 at 18:15
  • I'm curious though; is your site solely coded as `.html` files? Your question's pretty unclear, far as I'm concerned and is short on detail. – Funk Forty Niner Jul 30 '16 at 18:18

3 Answers3

5

Yes, you can do that. No issues that I see. PHP code would work similarly.

Example :-

<p><?php echo $myName; ?></p>

and

<?php echo $myName; ?>
<p>Something else here</p>

both will work correctly.

Akshay
  • 2,244
  • 3
  • 15
  • 34
3
       <div class="eight columns">
                <div class="padding-right">
                    <p id="address"><?php echo "Hello"; ?></p>

                </div>
       </div>

Yeah, you can do that.

    <div class="sample">
          <p> Here goes the php code<br>
            <?php 
              date_default_timezone_set("America/New_York");
              echo "Today is".date("d-m-Y"); 
            ?>
         </p>
    </div>

Hope it will help you.

Sampad
  • 1,645
  • 11
  • 14
2

Short answer - yes. You can interleave <?php> tags inside any HTML tag.

Mureinik
  • 297,002
  • 52
  • 306
  • 350