Is there a way to load a file (copyright.php
) functions & variable's value into child theme's functions.php
I'm trying to pass the value in order to change the footer credit. I can do it if I included the code directly within functions.php
, but I'm trying to exclude the code to a different file so that my client can change the variables value easily in the future without touching functions.php
. Below are my codes but it's not working:
copyright.php (within Child Theme folder)
function display_company_url() {
global $company_url;
$company_url = 'www.mycompany.com';
return $company_url;
}
function display_company_name() {
global $company_name;
$company_name = 'MY COMPANY';
return $company_name;
}
functions.php (Child Theme)
add_action( 'wp_enqueue_scripts', 'my_assets' );)
function my_assets() {
wp_register_script( 'copyright', get_stylesheet_directory_uri() . '/copyright.php' );
wp_enqueue_script( 'copyright' );
}
// REMOVE AND MODIFIED PARENT'S FOOTER
add_action( 'init', 'remove_parent_footer', 10);
function remove_parent_footer() {
remove_action('parent_footer', 'parent_footer_credits', 8);
add_action('parent_footer', 'child_footer_credits', 8);
function child_footer_credits() {
?>
<div class="site-info col-md-6">
<a href="<?php echo esc_url( __( '/login', 'childtheme' ) ); ?>" rel="nofollow"> <?php echo "Copyright" ?></a> © <?php echo date("Y"); ?>
<?php echo get_bloginfo( 'name' ) . ". All rights reserved."; ?> <br> <?php echo "Powered by"; ?>
<a href="<?php echo esc_url( __( display_company_url(), 'childtheme' ) ); ?>" rel="nofollow"><?php echo display_company_name(); ?></a>
</div><!-- .site-info -->
<?php
}
}
The footer credit should be showing:
Copyright © 2017 BLOGNAME. All rights reserved.
Powered by MY COMPANY
dashboard -> Add pages
and call that page in footer.php. This way client can change contents most easily.