There are many ways to figure this out. I think, based on your comments the best solution is to use purely hooks. I'm still not exactly sure what you're adding, here are some ideas. (your suggestion of including the page.php in a separate page just won't work because all code is being pulled from the page.php already.
1. add custom code to the footer of a set page. (hooked wp_footer)
In your child theme's functions.php add this code:
function dd_custom_function() {
if (is_page('services')) { //add your slug or id or other conditional here that you want to call your code
echo '<p>This is inserted at the bottom</p>';
}
}
add_action( 'wp_footer', 'dd_custom_function');
(if you want to add to the header, change wp_footer
to wp_header
)
2. Put your code in a separate file and pull it into your footer.
add the code file custom.js
to your child theme directory in /js/ (create that directory)
add this code to your functions.php of your child theme: (choose one of the wp_enqueue lines..one is for the header one is for the footer.)
function dd_enqueue_function() {
if (is_page('services')) { //add your slug or id or other conditional here that you want to call your code
wp_enqueue_script('creative-blog-main-script', get_stylesheet_directory_uri() . '/js/custom.js', array('jquery'), null, true); // Here in this example the last value has been set as true, so, it will be loaded in the footer.
wp_enqueue_script('creative-blog-script', get_stylesheet_directory_uri() . '/js/custom.js', array('jquery'), null, false); // Here in this example the last value has been set as false, so, it will be loaded in the header.
}
}
add_action('wp_enqueue_scripts', 'dd_enqueue_function');
3. See if your theme has any actions set you can a hook into.
Many themes will set actions for you that you can hook into. It may even be in the footer.php look for do_action
and use those actions to place your custom code.
If it doesn't, you could add one line to the page.php file:
do_action('dd_cool_action');
wherever you want the code to execute.
Then in your child 'custom function call the code to action:
add_action('dd_cool_action', dd_custom_function', 5);
function dd_custom_function { ?>
<div> Drew David custom code activated </div>
<?php }
include
to pull in page.php and then just adding my JSON LD eg below that??