Add Alt attribute to featured image

HotNews theme integrates four thumbnail modes: adding custom columns, calling designated pictures, characteristic images, automatically obtaining the first picture in the log, and random thumbnails to meet different use needs. Among them, Wordpress feature image function does not have Alt attribute by default. Since I seldom use feature image function, I don't pay much attention to it. Search engines mainly rely on alt attribute to judge the meaning of images, so this attribute is still very important.

The following provides methods for adding Alt attributes:

Open the thumbnail.php template of the HotNews topic HotNewspro includes directory, and then:

  1. <? php  if  (has_post_thumbnail()) { the_post_thumbnail('thumbnail'); }  

Replace with:

  1. <? php  if  (has_post_thumbnail()) { the_post_thumbnail('thumbnail' , array ('alt'=> trim( strip_tags $post ->post_title )), 'title'=> trim( strip_tags $post ->post_title ))));}   

It seems that there are similar problems in other parts of the theme, which will be corrected when the theme is upgraded next time.

Tips:

To modify the theme, please go to the background - Appearance - Editing or use special editing software. It is recommended to use free Notepad++

The Chinese theme template code is: UTF-8 without BOM Otherwise, the modification will cause dislocation.

 

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
WeChat copied
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
Comments sixty-five    Visitors fifty-four    Author eleven
    •  Li Zipeng
      Li Zipeng three

      Since the theme will be upgraded with this function next time, we won't bother this time.

      •  Tumei
        Tumei three

        I found that Brother Bird did a good job in user experience optimization and cared about it very much. Support Brother Bird.

        I don't know that Brother Bird found that there is a user experience problem without a template. If the website is viewed with a 1024 × 768 resolution display, the width of the website page is the same as that of the website viewed with a 1268 × 1024 resolution display
        I wonder if it is difficult for the website to automatically adjust the width of the website page according to the size of the user's display resolution? What should we do?

          •  Robin
            Robin

            @ Tumei As the saying goes: It is not difficult for those who can, and it is not difficult for those who can
            You can take a look at this
            http://zmingcx.com/the-adaptive-web-design-responsive-web-design.html
            PS: Neither do I

              •  Tumei
                Tumei three

                @ Robin I supported and learned a little more

            •  Miracle Private Service
              Miracle Private Service one

              This is good~~

              •  tumaii
                tumaii three

                Let me at least test whether my message avatar can be displayed

                  •  moonfly
                    moonfly two

                    @ tumaii It seems that the test failed. The avatar is not displayed!

                  •  Gothic revival
                    Gothic revival four

                    Wait another time

                    •  Changyang Time
                      Changyang Time four

                      Etc~

                      •  Salon
                        Salon four

                        A simple and important piece of code, but my site does not use featured images, which does not affect

                        •  Hu Shezhong
                          Hu Shezhong three

                          Recommended topic Suffusion – 4.4.4, Chinese reference http://www.wang3feng.com/ Chinese package, my website www.gaac.cc

                          •  Houdao computer
                            Houdao computer zero

                            The filing took a long time

                            •  Hua Zimao
                              Hua Zimao two

                              How long will it take to upgrade the theme?

                              •  ocean waves
                                ocean waves zero

                                Come to see Brother Bird
                                I also look forward to your return visit

                                •  Late summer
                                  Late summer four

                                  Support Brother Bird!

                                  •  Down Jackets
                                    Down Jackets four

                                    The building owner's code is very powerful

                                    •  Four five networks
                                      Four five networks three

                                      Baidu webmaster tool website optimization mentioned the image Alt attribute, which is conducive to the search engine to capture information

                                      •  Ludovic
                                        Ludovic one

                                        Brother Bird, I don't know what the problem is.
                                        After using your code, the featured images do have the ALT attribute, but the location of the featured images on the home page is wrong. They are basically moved down a bit, which looks very untidy.

                                          •  Robin
                                            Robin

                                            @ Ludovic See the tips at the end of this article

                                              •  Ludovic
                                                Ludovic one

                                                @ Robin Well, is it a coding problem
                                                I specially saved it in UTF-8 format after modification.
                                                Thank you for your reply first. I'll try again.

                                            •  Mr. wordpress
                                              Mr. wordpress four

                                              Blogger, I really want to use your hot news topics, but why does the homepage not display once it is set to CMS. Most websites can't be opened, and the homepage can be displayed normally in blog mode! Please give me a reply!

                                              •  Sunshine Computer Information Network
                                                Sunshine Computer Information Network one

                                                The Alt attribute is very important. The search engine seems to care about this

                                                •  Midi
                                                  Midi two

                                                  I haven't paid attention to the problem of the Alt attribute. Let's update it next time

                                                  •  Anti piracy
                                                    Anti piracy one

                                                    Bird brother's website finally came back, celebrate!!! Is the domain name expired?

                                                    •  Tumei
                                                      Tumei three

                                                      Brother Bird, ask me, so as to control the number of words displayed in the "summary"...
                                                      I think this only displays 90 characters. Write the code like this?

                                                        •  Tumei
                                                          Tumei three

                                                          @ Tumei 《Ph p?php the_excerpt() ?》 Brother Bird, this code can't be displayed at all!

                                                          •  Robin
                                                            Robin

                                                            @ Tumei For example, modify the template of the classification page, open the archive, and find something similar:

                                                            echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 400,“…”);   
                                                            Modify the following numbers
                                                            Other page modifications are the same

                                                              •  Tumei
                                                                Tumei three

                                                                @ Robin Brother Bird, thank you for looking for the source code
                                                                My problem is that I need to modify the "summary". What you control above is the number that controls the display of article content

                                                                  •  Robin
                                                                    Robin

                                                                    @ Tumei The "summary" you said needs to be added manually. It's just a matter of adding a few words

                                                                      •  Tumei
                                                                        Tumei three

                                                                        @ Robin How do you say this?
                                                                        But thank you first, Brother Bird

                                                                •  Mr. Zhang Lei
                                                                  Mr. Zhang Lei zero

                                                                  This theme is so good, but I can only wait and see, I can't use it myself! I don't know what's going on! Cms cannot be enabled on the home page. Once enabled, http500 error occurs! Other blog pages can be accessed normally!

                                                                  •  Download pptv player
                                                                    Download pptv player one

                                                                    This function is really practical.

                                                                    •  Mr. Zhang Lei
                                                                      Mr. Zhang Lei four

                                                                      Other cms themes can be used normally, that is, the homepage cms of this theme displays http500 errors! Other blog pages are normal!

                                                                      •  Mr. Zhang Lei
                                                                        Mr. Zhang Lei four

                                                                        Ask the blogger: what is the name of the plug-in in the picture and how to implement it. [img] http://www.zhangleisir.cn/wp-content/uploads/2013/01/20130118210526.png [/img]

                                                                        •  Mr. Zhang Lei
                                                                          Mr. Zhang Lei four

                                                                          Blogger, there is another question. Why is it not displayed on the friendship link page when friendship links are added?

                                                                            •  Robin
                                                                              Robin

                                                                              @ Mr. Zhang Lei You installed the self-service friend chain plug-in, set the display quantity

                                                                                •  Mr. Zhang Lei
                                                                                  Mr. Zhang Lei four

                                                                                  @ Robin Well, it's done. The original is to add a category of friendship links. The friendship links in the friendship page can be displayed normally!

                                                                                  •  Mr. Zhang Lei
                                                                                    Mr. Zhang Lei four

                                                                                    @ Robin I can't find the beautiful picture in the navigation of the blogger's blog in the background menu configuration! Neither in the category nor in the page! I hope the blogger will give me a reply, thank you!

                                                                                •  Mr. Zhang Lei
                                                                                  Mr. Zhang Lei four

                                                                                  Blogger, why does clicking on the image display this: Catechable fatal error: Object of class WP_Error could not be converted to string in/home/hhwhhutg/domains/zhanglisir.cn/public_html/wp content/themes/HotNewspro/single.php on line 13 instead of clicking on the image on your blog to enlarge it?

                                                                                  •  wmtimes
                                                                                    wmtimes seven

                                                                                    ok I will add this function again.

                                                                                    •  taikong007
                                                                                      taikong007 three

                                                                                      Brother Bird, after modification, what will the Alt of the picture change to?

                                                                                      •  Panda Family
                                                                                        Panda Family one

                                                                                        Indeed, alt can provide more information about SEO

                                                                                        •  Godaddy Coupon Code
                                                                                          Godaddy Coupon Code one

                                                                                          Alt seems to be more effective for Google's image search. Although Durian also suggests adding it, it has no effect

                                                                                          •  Recommended hiking shoes
                                                                                            Recommended hiking shoes zero

                                                                                            Boss, how can I make a category not displayed on the home page? Which code should be changed in CMS mode? thank!!

                                                                                              •  Robin
                                                                                                Robin

                                                                                                @ Recommended hiking shoes In CMS mode, basically each module can display customized content. Get familiar with the theme setting panel

                                                                                              •  Drunk wind and cloud
                                                                                                Drunk wind and cloud two

                                                                                                Come and have a look

                                                                                                •  Wealth management expert
                                                                                                  Wealth management expert two

                                                                                                  Brother Bird, how are your website links set? How to realize multi-level links?
                                                                                                  My site fixed connection settings are http://www.ccwseo.net/%post_id%.html
                                                                                                  All pages can only have one "/". How to achieve the same goal as your website? Multiple "/" can appear behind the domain name http://zmingcx.com/category/hotnewspor
                                                                                                  I can only scratch the surface of the website, which makes you laugh

                                                                                                  I mainly want to create a new page with only articles related to the page title
                                                                                                  For example, your website: [Technical Analysis - HotNews Topic] This page displays articles related to [HotNews Topic]. I want to achieve this goal. Thank you for your answers

                                                                                                  •  Tencent
                                                                                                    Tencent zero

                                                                                                    Catchable fatal error: Object of class WP_Error could not be converted to string in /home1/vhost/vh543034/www/3qia/wp-content/themes/HotNewspro/single.php on line 13
                                                                                                    Solve

                                                                                                    •  Frank
                                                                                                      Frank zero

                                                                                                      I really like HotNewsPro2.7. Thanks for sharing! When I tried to use Windows Live Writer to connect to this topic for offline editing, the wlw was not very easy to use. The main reason was that the editing area was abnormal. I tried other topics without problems. I wanted to know why. Thank you!

                                                                                                        •  Robin
                                                                                                          Robin

                                                                                                          @ Frank First, learn how to use wlw
                                                                                                          Re reference:
                                                                                                          http://zmingcx.com/hotnewspro24-problem-summary.html
                                                                                                          Article 22

                                                                                                        •  Zhu
                                                                                                          Zhu zero

                                                                                                          Little by little, I suggest that old birds should update new knowledge. New birds know little

                                                                                                          •  wancad
                                                                                                            wancad one

                                                                                                            The theme is very classic. I learned from the blogger.

                                                                                                            •  Elephant seo
                                                                                                              Elephant seo zero

                                                                                                              Brother Bird, is it under the theme directory? Why can't I find this file

                                                                                                             anonymous

                                                                                                            Comment

                                                                                                            Anonymous netizens
                                                                                                             :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

                                                                                                            Drag the slider to complete validation