How do I declare a variable in PHP without displaying its value in my html? -


i working in wordpress website , need pass url of page argument of function. in case using

bloginfo('url'); 

to retrieve base url of site.

so code is

<?php   $portfolio_link = bloginfo('url');  if ( ! function_exists( 'ow_nav' ) ) {     function ow_nav( $nav_position ) {         ?>         <nav id="ow-nav-<?php echo $nav_position; ?>" class="ow-nav clearfix ow-nav-<?php echo $nav_position; ?>">             <ul class="ow-nav-list">                 <?php ow_nav_item( '#home',         'home'                ); ?>                 <?php ow_nav_item( '#about',        'about'               ); ?>                 <?php ow_nav_item( '#criteria',     'investment criteria' ); ?>                 <?php ow_nav_item( '#approach',     'approach'            ); ?>                 <?php ow_nav_item( '#team',         'team'                ); ?>                 <?php ow_nav_item( $portfolio_link, 'portfolio'           ); ?>             </ul>         </nav>         <?php     } }  if ( ! function_exists( 'ow_nav_item' ) ) {     function ow_nav_item( $link, $text ) {         ?>         <li>             <a href="<?php echo $link; ?>">                 <span class="ow-txt"><?php echo $text; ?></span>                 <span class="ow-dot"></span>             </a>         </li>         <?php     } } 

but when that, variable gets leaked in html, displaying url in random place in dom.

any ideas?

bloginfo() automatically echoes returned value, have seen. return value , store in variable, need use get_bloginfo() instead, e.g.:

$portfolio_link = get_bloginfo('url'); 

bloginfo ref: https://developer.wordpress.org/reference/functions/bloginfo/
get_bloginfo ref: https://developer.wordpress.org/reference/functions/get_bloginfo/

note: come across many wordpress functions this, 1 version automatically display value , second version (usually preceded get_) return value e.g. the_title / get_the_title


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -