dongtieshang5429 2014-08-02 17:01
浏览 64
已采纳

如果默认值为空,Wordpress PHP将使用网站标题替换图像

I am making options in the 'customization api' for Wordpress. However for things such as the logo image, if no image has been uploaded (default value is blank) i want it to display the title of the Wordpress site. I have searched google a lot, but I just cant seem to get it to work.

I know the PHP code for the Wordpress site title, but I can't get the php 'if' and 'else' to work.

current code:

<img src="<?php echo get_theme_mod('logo_image'); ?>" alt="<?php bloginfo('name'); ?>"/>

..obviously this is just the option to upload the image, which WORKS, but I want it to display the site title if the default value is empty.

Thank you!

  • 写回答

2条回答 默认 最新

  • dongzhenju3015 2014-08-04 12:26
    关注

    I don't know how you are setting the theme mod. I.e. are you using 'set_theme_mod' ?

    But assuming you are complying to WordPress standards the code snippet below should be what you are seeking.

    if (!empty(get_theme_mod('logo_image'))) {
        echo "<img src='" . get_theme_mod('logo_image') . "' title='" . bloginfo('name') ."'>"
    } else {
        echo "<h2>" . bloginfo('name') . "</h2>";
    }
    

    Hope this helps you out, Dave.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧