php - WP Fatal error: Call to undefined function get_template_directory_uri()

admin2025-01-07  4

theme: functions.php

function one_admin_menu() {
    add_menu_page( 
        'One Dashboard',
        'One',
        'manage_options',
        'one_menu',
        'one_menu_url',
        'dashicons-admin-site',
        1
    ); 
} 
add_action( 'admin_menu', 'one_admin_menu' );

function one_menu_url() {
    include( get_template_directory() . '/includes/admin/main_one/main.php' );
}

main.php

<?php  
function one_admin_website() {
    $web = get_template_directory_uri() . '/includes/admin/main_one/website.php';
    echo $web;
}
?>

<script>
    function import_admin_menu(when, where, what) {
        jQuery(document).ready(function() {
            jQuery(when).click(function() {
                jQuery(where).load(what);
            });
        });
    }
</script>
<ul>
    <li id='website'><a href="#about">Website</a></li>
</u>
<script>
    import_admin_menu('#website', '#one_main_admin', '<?php one_admin_website() ?>' ) 
</script>
<div id='one_main_admin'> </div>

website.php

my problem is here, just trying to echo template directory and i having Fatal error: Uncaught Error: Call to undefined function get_template_directory_uri()

<?php echo get_template_directory_uri(); ?>

what i made wrong? i have try to search in google in stackoverlow, but didin't found anything. thank you for your time

theme: functions.php

function one_admin_menu() {
    add_menu_page( 
        'One Dashboard',
        'One',
        'manage_options',
        'one_menu',
        'one_menu_url',
        'dashicons-admin-site',
        1
    ); 
} 
add_action( 'admin_menu', 'one_admin_menu' );

function one_menu_url() {
    include( get_template_directory() . '/includes/admin/main_one/main.php' );
}

main.php

<?php  
function one_admin_website() {
    $web = get_template_directory_uri() . '/includes/admin/main_one/website.php';
    echo $web;
}
?>

<script>
    function import_admin_menu(when, where, what) {
        jQuery(document).ready(function() {
            jQuery(when).click(function() {
                jQuery(where).load(what);
            });
        });
    }
</script>
<ul>
    <li id='website'><a href="#about">Website</a></li>
</u>
<script>
    import_admin_menu('#website', '#one_main_admin', '<?php one_admin_website() ?>' ) 
</script>
<div id='one_main_admin'> </div>

website.php

my problem is here, just trying to echo template directory and i having Fatal error: Uncaught Error: Call to undefined function get_template_directory_uri()

<?php echo get_template_directory_uri(); ?>

what i made wrong? i have try to search in google in stackoverlow, but didin't found anything. thank you for your time

Share Improve this question asked Jan 5, 2017 at 13:22 Tester01Tester01 111 silver badge3 bronze badges 1
  • 1 Are you loading website.php directly? – Tom J Nowell Commented Jan 5, 2017 at 14:51
Add a comment  | 

2 Answers 2

Reset to default 0

Please check your domain. In my case url is like this.

http://xxx.local/wp-content/themes/{your_teme}

change to

http://xxx.local/

It fixed. Sometimes wrong url cause this problem.

get_template_directory_url

no

get_template_directory_uri

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736256284a349.html

最新回复(0)