2

I'm trying to execute a PHP script which is located in home directory of WordPress.

For example run.php

<?php echo 'i run'; ?>

I want to run this page in URL mysite.com/run.php but it says 404 not found, even the run.php is located in that address.

What am I doing wrong?

  • 2
    Typically, WordPress does not get in the way of direct access to files like that, so long as there are no naming conflicts, so I suspect something peculiar about your site. That is a different question that whether this is a good idea or not, and it usually isn't. Please explain what you are trying to accomplish in more detail. – s_ha_dum May 4 '14 at 2:00
  • 1
    Generally speaking there are 2 (good) options in Wordpress: 1) Put in (your) code to execute in the functions.php file of the active theme (located in wp_content/themes/<theme name>/ OR 2) Make a plugin and put your code in the plugin and activate the plugin. I would recommend start reading here... codex.wordpress.org/Functions_File_Explained – bestprogrammerintheworld May 4 '14 at 7:18
3

If you want to add custom page in WordPress, you need to add your custom PHP file into currently activated theme ( /wp-content/themes/ ) folder.

Suppose you have child-theme. Put the file to child-theme folder. Then goto page section, Click Add New.

In Page Attributes, Choose Template as your PHP File.

Open the Page.php file, It's available from the theme folder. Copy the all thing except header and paste it into your PHP file. Your PHP file must need following codes.

<?php /* Template Name: CustomPageT1 */ ?>

<?php get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php
        // Start the loop.
        while ( have_posts() ) : the_post();

            // Include the page content template.
            get_template_part( 'template-parts/content', 'page' );

            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) {
                comments_template();
            }

            // End of the loop.
        endwhile;
        ?>

    </main><!-- .site-main -->

    <?php get_sidebar( 'content-bottom' ); ?>

</div><!-- .content-area -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy