简体   繁体   English

如何在 wordpress 页面上打印 'bloginfo('url')'

[英]How can i print 'bloginfo('url')' on a wordpress page

Basically I do not want to enter www.domain.cl on the page, but to have a constant that contains the value www.domain.cl.基本上我不想在页面上输入 www.domain.cl,而是想有一个包含值 www.domain.cl 的常量。 For example:例如:

the HTML <a href="www.domino.cl">HOME</a> HTML <a href="www.domino.cl">HOME</a>

to <a href="const">HOME</a> <a href="const">HOME</a>

On WordPress the solution is:在 WordPress 上,解决方案是:

 <?php
 <a href='<?php echo bloginfo("url ") ; ?>'>HOME</a>
 ?>

Or或者

 <?php
 <a href='<?php echo site_url() ; ?>'>HOME</a>
 ?>

You can use PHP Constant.您可以使用 PHP 常量。 See the below link.请参阅以下链接。

https://www.w3schools.com/php/php_constants.asp https://www.w3schools.com/php/php_constants.asp

So, you can get the site name in any of your files.因此,您可以在任何文件中获取站点名称。

Put the below code in your header.php file.将以下代码放在 header.php 文件中。

<?php
    $siteName = site_url();
    define( 'SITE_NAME', $siteName );
?>

and, you can get the Site URL like this.并且,您可以像这样获取站点 URL。

<a href="<?php echo SITE_NAME; ?>">HOME</a>

This is for reference这是供参考

 <?php
 $url = "www.domino.cl";
 ?>

 <a href='<?php echo $url; ?>'>HOME</a>

OR或者

<?php
const URL = "www.domino.cl";
?>
<a href='<?php echo URL; ?>'>HOME</a>

Please try this code for reference:-请尝试此代码以供参考:-

<a href="<?php echo bloginfo('url'); ?>">home</a>

OR

<a href=" <?php echo get_home_url(); ?>">home</a>

Create custom function km_get_blog_posts_page_url() in functions.php file.在functions.php 文件中创建自定义函数km_get_blog_posts_page_url()。 Please refer below link.请参考以下链接。

<?php
/**
 * Get blog posts page URL.
 *
 * @return string The blog posts page URL.
 */
function km_get_blog_posts_page_url() {
    // If front page is set to display a static page, get the URL of the posts page.
    if ( 'page' === get_option( 'show_on_front' ) ) {
        return get_permalink( get_option( 'page_for_posts' ) );
    }
    // The front page IS the posts page. Get its URL.
    return get_home_url();
}

This is the source of the above code.这是上述代码的来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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