How can I place dynamic text inside a PHP include function? Since I cannot place PHP inside PHP I am stumped. Code below:
[php]
<?php include(ABSPATH."path/[DYNAMIC_TEXT]/file.php") ?>[/php]
Thanks!
How can I place dynamic text inside a PHP include function? Since I cannot place PHP inside PHP I am stumped. Code below:
[php]
<?php include(ABSPATH."path/[DYNAMIC_TEXT]/file.php") ?>[/php]
Thanks!
What do you mean you “can’t place php inside php”?
You use concatenation in your code already, just do the same for the dynamic text part and you’re good to go.
My mistake then. So can I do this?
[php]
<?php include(ABSPATH."<?php the_field('file_path'); ?>/file.php")?>
[/php]
[php]<?php
include(ABSPATH . the_field(‘file_path’) . “/file.php”)[/php]
Thanks Jim.
That isn’t working. Although the file_path is displaying on the page, right at the very top (not sure if that is part of the error reporting?). It appears it is looking for the file.php but without the file_path preceding it. The file is located at /var/www/vhosts/mydomain.com/httpdocs/file/path/file.php
Here is the error reporting:
[code]file/path/
Warning: include(/var/www/vhosts/mydomain.com/httpdocs/file.php): failed to open stream: No such file or directory in /var/www/vhosts/mydomain.com/httpdocs/wp-content/themes/canvas/page-template.php on line 20
Warning: include(): Failed opening ‘/var/www/vhosts/mydomain.com/httpdocs/file.php’ for inclusion (include_path=’.:’) in /var/www/vhosts/mydomain.com/httpdocs/wp-content/themes/canvas/page-template.php on line 20[/code]
Some background, the the_field(‘file_path’) is a parameter from Wordpress Custom Fields to insert the text from a custom field into a page.
Does the_field(‘file_path’) output what you expect on that page? (var dump it).
Forgive my noobism if i’m doing this wrong.
[php]var_dump(the_field(‘file_path’))[/php]
Returns:
file/pathNULL
Why dont you just do:
[php]<?php
include("/var/www/vhosts/mydomain.com/httpdocs/file/path/file.php")
?>[/php]
Hey Kevin,
I need the text to dynamically change so that way won’t work. That said, the page does work correctly when I insert the path as you have it.
What does this output
[php]var_dump(ABSPATH . the_field(‘file_path’) . “/file.php”);[/php]
string(52) “/var/www/vhosts/mydomain.com/httpdocs//file.php” file/path
Anyone?
Looks like I will post this in the PHP for hire section next.