It sounds like you are just trying to output specific content, which you have in non-WP PHP files right now, on a specific page.
If that’s the case, the most straightforward way will be to create a custom WP plugin. All you need to do is add a folder inside your /wp-content/plugins/
folder with a PHP file that contains a simple comment:
<?php
/**
* Plugin Name: Control Text
* Version: 1.0.0
*/
Activate it in the wp-admin Plugins screen so you don’t forget to do so and wonder why your script isn’t working.
From there, it depends what your current scripts are doing and where you want to have them run. If you are generally wanting to output content inside the theme – like page content in between a header and a footer – you will probably use a hook like the_content
.
For example, if one of your scripts currently contains the following (very simplified) logic:
<?php
$number = 1;
if ( $number > 0 ) {
return 'My number is an integer.';
} else {
return 'Not an integer.';
}
you can show that output on a particular WP Page by wrapping your code in a function inside that plugin.php
file you just created, and then telling WP to run it when it outputs main content:
<?php
/**
* Plugin Name: Control Text
* Version: 1.0.0
*/
// Check whether a number is an integer and return the result.
function check_integer() {
$number = 1;
if ( $number > 0 ) {
return 'My number is an integer.';
} else {
return 'Not an integer.';
}
}
// Run the Check Integer function.
add_filter( 'the_content', 'check_integer' );
You probably want one additional step – identifying exactly where this content is output. Right now it would output on every page and post. If you create a Page at http://www.example.com/integer/ then the page slug is “integer” and you can update your function like so:
// Pass the existing $content into the function.
function check_integer( $content ) {
// Only run on the 'integer' page.
if ( is_page( 'integer' ) ) {
$number = 1;
if ( $number > 0 ) {
return 'My number is an integer.';
} else {
return 'Not an integer.';
}
}
// If we're not on the 'integer' page, return the normal content.
return $content;
}
Obviously your logic may be much more complex, but basically, you are likely to do best by: creating a plugin, hooking it to the the_content
filter, adding conditionals to target which pages you actually want to display content on, and putting your real code inside those conditionals.