Can I get a “base URL” in WordPress within a template file?

前端 未结 5 653
有刺的猬
有刺的猬 2021-02-01 03:57

Usually in my PHP apps I have a base URL setup so I can do things like this

tom/jones\">Tom


        
相关标签:
5条回答
  • 2021-02-01 03:58

    Yes, you can use get_bloginfo('url') just like that or define a constant...

    define('BASE_URL', get_bloginfo('url'));
    

    If you are working on a template and want the URL fragment to that theme folder, use...

    bloginfo('template_directory'); 
    
    0 讨论(0)
  • 2021-02-01 03:59

    get_bloginfo('wpurl'); would be the preferred method of getting the base url of your WordPress installation. This always returns the absolute base url for the install where as get_bloginfo('url'); is for the actual blog address of your WordPress install.

    0 讨论(0)
  • 2021-02-01 04:01

    You can try using

    <?php echo home_url(); ?>
    

    By using this can get site url like www.xyz.com

    <?php echo home_url('/contact'); ?>
    

    By using this syntax you will get url like www.xyz.com/contact

    0 讨论(0)
  • 2021-02-01 04:04

    Yes you can get "base URL" with a simple function.

    <?php echo get_bloginfo('url') ?>
    

    after that with / you can reach to any page just type the page name.

    0 讨论(0)
  • 2021-02-01 04:18

    You can use the built in wordpress function site_url() which retrieves the URL for the current site.

    Take a look at site_url for more details.

    EX:

    <a href="<?php echo site_url('tom/jones'); ?>">Tom</a>
    
    0 讨论(0)
提交回复
热议问题