# Elements and php-code

**URL:** <https://forums.realmacsoftware.com/t/elements-and-php-code/46409>\
**Category:** RapidWeaver Elements\
**Created:** [February 22, 2025, 9:21am UTC](https://forums.realmacsoftware.com/t/elements-and-php-code/46409 "2025-02-22T09:21:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pegasus](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/pegasus/32/25035_2.png) [@Pegasus](https://forums.realmacsoftware.com/u/Pegasus)\
**Post date:** [February 22, 2025, 9:21am UTC](https://forums.realmacsoftware.com/t/elements-and-php-code/46409/1 "2025-02-22T09:21:27Z")

</div>

i use rw-classic very intensively and have just started playing around with rw-elements. I have found that some of the functions I need to convert my projects to rw elements are not currently working.

i very often use PHP code in my content and meta tags (title & description) to generate dates dynamically, for example like this:

`<?php echo date("Y"); ?>`  
or  
`<?php echo date ("d.m.Y", strtotime("Monday this week"))?>`

Although I have changed my test project under “default extensions” from .html to .php, the code is not output accordingly.

i know that rw-elements is currently still in the beta phase. will it be possible to use php code in the content and meta-tags in the future?

---

<div class="post-metadata">

**Author:** ![Beblebroks](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@Beblebroks](https://forums.realmacsoftware.com/u/Beblebroks)\
**Post date:** [February 22, 2025, 9:35am UTC](https://forums.realmacsoftware.com/t/elements-and-php-code/46409/2 "2025-02-22T09:35:51Z")

</div>

Hi @Pegasus,

I do not know what Rapidweaver is planning related to PHP and so on.

But in general I mostly use Javascript to achieve the stuff that you just mentioned. And that can also be achieved with Custom Components. So no need for a full PHP server.

Regards  
Nicolas

---

<div class="post-metadata">

**Author:** ![dan](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/dan/32/28516_2.png) [@dan](https://forums.realmacsoftware.com/u/dan)\
**Post date:** [February 22, 2025, 10:58am UTC](https://forums.realmacsoftware.com/t/elements-and-php-code/46409/3 "2025-02-22T10:58:59Z")

</div>

Yes, PHP will work in Preview. Elements has a built-in PHP server, just like Classic.

You’ll just need to ensure the file extension on your existing pages are set to .php

 ![CleanShot 2025-02-22 at 10 .57.20@2x](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/c/7/c7e17637e2d42a7be0af86a77a14efeb76e108f3.jpeg)

Let me know how you get on.

---

<div class="post-metadata">

**Author:** ![Pegasus](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/pegasus/32/25035_2.png) [@Pegasus](https://forums.realmacsoftware.com/u/Pegasus)\
**Post date:** [February 22, 2025, 11:24am UTC](https://forums.realmacsoftware.com/t/elements-and-php-code/46409/4 "2025-02-22T11:24:50Z")

</div>

@dan  
I can’t get it to run

see screenshots.

 ![Bildschirmfoto 2025-02-22 um 12.12.43](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/4/a/4a9d3f9746280f35000a67d5cefaced6f3154997.jpeg)  
 ![Bildschirmfoto 2025-02-22 um 12.16.59](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/c/b/cbc305d3cf56eb808170b9fd415e94d0c18e76c8.jpeg)  
 ![Bildschirmfoto 2025-02-22 um 12.17.49](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/1/6/16176d40c56b09f0a2faf6b5bf00dcb96231da8d.jpeg)  
 ![Bildschirmfoto 2025-02-22 um 12.20.25](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/0/0/00e2dddb2461f434db5fe613887ff271ca5f9ef9.jpeg)

---

<div class="post-metadata">

**Author:** ![dan](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/dan/32/28516_2.png) [@dan](https://forums.realmacsoftware.com/u/dan)\
**Post date:** [February 22, 2025, 11:43am UTC](https://forums.realmacsoftware.com/t/elements-and-php-code/46409/5 "2025-02-22T11:43:08Z")

</div>

Hey @Pegasus,

Yes, we’re better at encoding things in Elements now - PHP really shouldn’t be put into this field.

A better way to do this would be to put the PHP code into the site Template like this…

 ![CleanShot 2025-02-22 at 11 .39.05@2x](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/2/5/25418fcee869b93489e65f01ade435d8338d4a40.jpeg)

If you need it different on a per page basis you could remove the title attribute from the main Template and put it in the “Headers” code area on each page.

 ![CleanShot 2025-02-22 at 11 .41.20@2x](https://europe1.discourse-cdn.com/flex005/uploads/realmacsoftware1/original/3X/b/f/bf7f4ba35da329128bca31f9172c1669934547ac.jpeg)

Does that work for you?

---

<div class="post-metadata">

**Author:** ![logrunner](https://avatars.discourse-cdn.com/v4/letter/l/59ef9b/32.png) [@logrunner](https://forums.realmacsoftware.com/u/logrunner)\
**Post date:** [February 22, 2025, 11:43am UTC](https://forums.realmacsoftware.com/t/elements-and-php-code/46409/6 "2025-02-22T11:43:54Z")

</div>

@dan I have just tried that and it doesn’t work AFAICS?

---

<div class="post-metadata">

**Author:** ![dan](https://dub1.discourse-cdn.com/flex005/user_avatar/forums.realmacsoftware.com/dan/32/28516_2.png) [@dan](https://forums.realmacsoftware.com/u/dan)\
**Post date:** [February 22, 2025, 11:54am UTC](https://forums.realmacsoftware.com/t/elements-and-php-code/46409/7 "2025-02-22T11:54:07Z")

</div>

Ah, okay that should work, but I’ve just tested it and there is a slight bug… if PHP is inside of an HTML element it gets removed and not rendered. We’ll get that fixed.

In the meantime doing it like this in Headers area of the Page Settings does work…

```auto
<?php
echo "<title>";
echo date("l, F j, Y");
echo "</title>";
?>

```
