Forums

How to add a specific PHP script in my WordPress site ? (5 posts)

  1. jfoulquier
    Member
    Posted 2 months ago #

    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 ?

  2. esmi
    Member
    Posted 2 months ago #

    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.

  3. jfoulquier
    Member
    Posted 2 months ago #

    Thank you esmi. I get it.
    But I still have two questions :

    1. 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.
    2. 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 !

  4. esmi
    Member
    Posted 2 months ago #

    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.

  5. jfoulquier
    Member
    Posted 2 months ago #

    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(); ?>

Reply

You must log in to post.

About this Topic