开发者

Echo link in wordpress

开发者 https://www.devze.com 2023-03-20 06:50 出处:网络
I would like to add a link via custom post type so that an image appears based on the page template, but I can\'t seem开发者_Python百科 to show the link in between the img src, here is my php code for

I would like to add a link via custom post type so that an image appears based on the page template, but I can't seem开发者_Python百科 to show the link in between the img src, here is my php code for this:

<?php 
        $logoImg = print(get_post_meta($post->ID, 'Page Logo', true));
        if ( is_page_template('second_page.php')) {
           echo '<div class="middle-strip">' . '$logoImg' . '</div>';

        }else{
           echo '';
        }
    ?>


  1. Assign the value to $logoImg directly, "print" returns an integer, not the value .
  2. Use double quotes, or No quotes to print the value of $logoImg . Single quotes will just print the string $logoImg , and not its value.

This code would work :

<?php 
        $logoImg = get_post_meta($post->ID, 'Page Logo', true);
        if ( is_page_template('second_page.php')) {
           echo '<div class="middle-strip">' . $logoImg . '</div>';

        }else{
           echo '';
        }
    ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消