简体   繁体   中英

how to write php require_once `<?php bloginfo('url'); ?>/database.php`

In wordpress <?php bloginfo('url'); ?> <?php bloginfo('url'); ?> is the main page's url, then, how to write a require_once include <?php bloginfo('url'); ?> <?php bloginfo('url'); ?> Something I write like this is not worked :{

<?php require_once ( "".bloginfo('url')."/database.php"); ?>

The bloginfo function will echo the data, not return it. As such, you need to use the get_bloginfo function, as this simply returns the data.

For example:

<?php require_once (get_bloginfo('url') . '/database.php'); ?>

However, it should be noted that if you're trying to include a local file you should simply use the ABSPATH define, as this will return the base install directory, which is what I'm guessing you're attempting to do.

ie: If "database.php" is located in the root WordPress directory, then...

<?php require_once (ABSPATH . '/database.php'); ?>

... should work.

Our you could consider using home_url(); home_url

If you are just trying to access wordpress database if so use the global $wpdb variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM