【问题标题】:How to use post title as featured image's alt text in Wordpress?如何在 Wordpress 中使用帖子标题作为特色图片替代文本?
【发布时间】:2013-05-03 23:00:56
【问题描述】:

如何在 Wordpress 中使用帖子标题作为该帖子特色图片的替代文本?

请告诉我如何/在哪里可以调整 WordPress 核心文件来实现这一点,因为我现在使用的主题似乎对重写图像的 alt 标签的插件没有任何反应。 ..

谢谢!

【问题讨论】:

    标签: php image wordpress seo alt


    【解决方案1】:

    无需更改 WordPress 核心文件:)

    只需在您的主题中找到使用the_post_thumbnail() 函数并将其更改为:

    $title=get_the_title();
    the_post_thumbnail( array(150, 150),array( 'alt' =>$title) );
    

    【讨论】:

      【解决方案2】:

      用户850010

      你说得对。

      $title=get_the_title();
      the_post_thumbnail( array(150, 150),array( 'alt' =>$title) );
      

      这对你有用,亚历克斯,请检查一下。

      Alex,如果你只想显示特定的图像,那么使用这个代码

      <img src="'.wp_get_attachment_url( get_post_thumbnail_id($item->ID)).'" alt="'.$item->post_title.'" title="'.$item->post_title.'" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-30
        • 2016-08-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多