du9826 2019-08-15 10:33
浏览 87
已采纳

PHP函数返回=“”而不是/

I have got a wordpress instance and i want to set background image inline a html tag via php function.

The html is:

<div id="content" class="site-content" <?php echo get_background_for_single(get_the_ID(), is_single()); ?>>

The above html and php has the following output in browser:

<div id="content" class="site-content" style="background-image: url(" http:="" localhost="" wiese="" wp-content="" uploads="" 2019="" 06="" test.jpg");="">

In the functions.php i got:

function get_background_for_single($ID, $single) {

    if ($single == 1) {
        return 'style="background-image: url("' . get_the_post_thumbnail_url($ID) . '");';
    }
}

If i controll the output in a paragraph as follows, it is displayed correct:

<p><?php echo get_background_for_single(get_the_ID(), is_single()); ?><p>

It returns in a p tag:

style="background-image: url("http://localhost/wiese/wp-content/uploads/2019/06/test.jpg");

Why does the function return " ="" " instead of " / "? Perhaps it is a dump mistake, but i cannot see my mistake.

  • 写回答

1条回答 默认 最新

  • doufei0933 2019-08-15 10:49
    关注

    Changing my function to the following is the solution:

    function get_background_for_single($ID, $single) {
    
        if ($single == 1) {
            return 'style="background-image: url(&quot;' . get_the_post_thumbnail_url($ID) . '&quot;);"';
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败