How to add a specific PHP script in my WordPress site ?
-
Hello,
I’d like to add a specific PHP page, hand writted, on my WordPress site.
I want to do this because it’s a specific script which cannot be an article or a page.For example, my page would be at http://www.domaine.com/mypersonalscript/
Of course I’d like to have at least the header/footer of WordPress, since the page is still on the website.
Does someone know how to do this ?
-
A simple custom template that includes your file should work:
<?php /* Template Name: MyScript */ ?> <?php get_header(); ?> <div id="content"> <?php include $_SERVER['DOCUMENT_ROOT'].'path_to/myscript.php';?> </div> <?php endwhile; endif; ?> <?php get_sidebar(); ?> <?php get_footer(); ?>
Bear in mind that ‘path_to’ needs to be the file path from your document root to your script file – not a url.
Thank you esmi. I get it.
But I still have two questions :- where to save this document ? If I save it in my wp-content/themes/mycurrenttheme/something.php and try to access with http://www.mydomain.com/wp-content/mycurrenttheme/something.php, it gets an error which says that get_header doesn’t exist, which I understand.
- how can I tell my WordPress that this page has to be accessed with http://www.mydomain.com/something/ ? How to link this page to the page I just created with a specific url ?
Thanks !
where to save this document ?
wp-content/themes/mycurrenttheme/something.php is correct
try to access with http://www.mydomain.com/wp-content/mycurrenttheme/something.php, it gets an error which says that get_header doesn’t exist
Now you need to create a new page in WordPress. Give it a title and assign the new page template “MyScript” (see the Page Template dropdown). Publish that page and then view it.
Ok. i’ve been busy for few days, that’s why I come back now.
Thx for the details esmi, but when I create (or modify) a page, I don’t see any page template dropdown.
Here’s the content of something.php in wp-content/themes/mycurrenttheme/something.php
<?php /* Template Name: Something */ ?> <?php get_header(); ?> <div id="content"> Hello, world ! </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
- The topic ‘How to add a specific PHP script in my WordPress site ?’ is closed to new replies.