-2

I'm working with wordpress, and have stoped with a problem, I can't figure out how to deal with quotes and php code inside a string.

working code:

$wrap .= '<li class="qx-nav-logo">
                <a href="">
                    <img src="http://127.0.0.1/wordpress/wp-content/uploads/theme/logo-nav.svg" />
                </a>
            </li>';

what I want to apply, is the href attribute value inside 'a' tag

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

I tried with double quotes and signle insides, and other way, but I does not work.

could You write me, how does it have to be done?

1
  • 4
    why don't you just cut your string into several different pieces - so the URL-part is one by itself that you actually can give to esc_url? also: that's not PHP inside a string. that's HTML inside a string. which, for PHP, is just text without any meaning whatsoever. Commented Jan 9, 2017 at 15:04

2 Answers 2

1

You can concatenate the strings in such manner:

$wrap .= '<li class="qx-nav-logo">
                <a href="'.esc_url( home_url( '/' ) ).'">
                    <img src="http://127.0.0.1/wordpress/wp-content/uploads/theme/logo-nav.svg" />
                </a>
            </li>';
Sign up to request clarification or add additional context in comments.

Comments

0

As @FranzGleichmann commented, It can be done differently and this is probably the best way, just to save our url to some variable first and than put it in place.

  $homeurl = esc_url( home_url( '/' ) );

  $wrap .= "<li class='qx-nav-logo'>
                <a href='{$homeurl}'>
                    <img src='http://127.0.0.1/wordpress/wp-content/uploads/theme/logo-nav.svg' />
                </a>
            </li>";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.