【问题标题】:Use dynamic site URLs in WordPress posts?在 WordPress 帖子中使用动态网站 URL?
【发布时间】:2023-03-09 11:54:01
【问题描述】:

我正在制作一个 WordPress 博客,我必须经常更改站点 URL 以进行测试。有没有一种有效的方法可以将博客的当前主页 URL 动态插入到帖子中?

例如我想做这样的事情:

[button link="[current_site_url]/about/" size="large"]About[/button] 

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    我认为<?php bloginfo('url'); ?> 是你要找的...

    您还可以使用

    获取模板目录的 url

    <?php bloginfo('template_directory'); ?>

    要查看bloginfo的其他参数请参考;

    http://codex.wordpress.org/Function_Reference/bloginfo

    【讨论】:

      【解决方案2】:

      这里有一些例子:

      //All these functions return the blog's URL as configured in Settings 
      site_url(); // Does not display the URL
      get_bloginfo('url'); // Does not display the URL
      bloginfo('url'); // Always displays the URL
      
      // Returns the root directory URL 
      // For http://example.com/myblog returns http://example.com 
      home_url(); // Does not display the URL
      

      【讨论】:

        猜你喜欢
        • 2010-11-24
        • 1970-01-01
        • 1970-01-01
        • 2018-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-10
        • 2021-10-13
        相关资源
        最近更新 更多