Change WordPress background editor style to realize direct preview

WordPress fifty-two 13.4K Reading mode

After WordPress 3.0, there is a new practical function: you can change the style of the default background editor (TinyMCE) to implement an interesting function: directly preview the layout of the log content in the background visual editor mode, and maintain the consistency with the foreground browsing style. You do not need to go to the foreground to view the log editing. WordPress 3.21 default theme Twenty Eleven has integrated this function. The default theme Twenty Eleven has powerful functions and integrates many new WordPress functions. So far, I haven't studied it thoroughly Children's shoes with the theme of WP might as well study more.

Open the default theme TwentyEleven's functions.php, and you will see a clearly commented code:

  1. // This theme styles the visual editor with editor-style.css to match the theme style.
  2. add_editor_style();

The general meaning of the note in Chinese is: the visual editor matches the style of the theme editor-style. css.

The key is this sentence. Take the HotNews Pro theme as an example to easily implement this function.

First, create a new file named editor-style.css, copy the following style into it, or download it directly: Editor-style.css file , and put it in the HotNews Pro theme css directory.

  1. body {
  2.      font 13px 'Microsoft YaHei', Microsoft YaHei Arial , Lucida Grande,  Tahoma sans-serif ;
  3.      color #000 ;
  4.      text-shadow 0px   1px   0px   #d1d1d1 ;
  5.      width 700px ;
  6.     }
  7. ul li{
  8.      list-style square   inside ;
  9.      line-height : 24px ;
  10.     }
  11. h1 { font-size 18px ; line-height :185%;}
  12. h2 { font-size 16px ; line-height :185%;}
  13. h3 { font-size 14px ; line-height :185%;}
  14. ul,ol,dd, pre ,hr {
  15.      margin : 0 0  10px  0;
  16.     }
  17. p {
  18.      line-height :185%;
  19.      text-indent :2em;
  20.      margin : 0 0  10px  0;
  21.     }
  22. blockquote {
  23.      width 660px ;
  24.      color #4e6384 ;
  25.      line-height 23px ;
  26.      margin 5px   auto   5px   auto ;
  27.      padding 10px ;
  28.      clear both ;
  29.      border 1px   solid   #ccc ;
  30.     }
  31. code  {
  32.      width 660px ;
  33.      font 12px / 17px   tahoma arial sans-serif ;
  34.      color #4e6384 ;
  35.      display block ;
  36.      margin 5px   auto   5px   auto ;
  37.      padding 10px ;
  38.      border-left 3px   solid   #8391A7 ;
  39.      border-right 1px   solid   #8391A7 ;
  40.      border-top 1px   solid   #8391A7 ;
  41.      border-bottom 1px   solid   #8391A7 ;
  42.     }
  43. blockquote td{
  44.      border-bottom 1px   solid   #ccc ;
  45.      padding 2px ;
  46.     }
  47. /**Mixed arrangement of pictures and texts**/
  48. img.centered  {
  49.      display block ;
  50.      margin-left auto ;
  51.      margin-right auto ;
  52.      margin-bottom 10px ;
  53.     }
  54. img.alignnone {
  55.      margin : 0 0  10px  0;
  56.      display inline ;
  57.     }
  58. img.alignright {
  59.      margin : 0 0  10px   10px ;
  60.      display inline ;
  61.     }
  62. img.alignleft {
  63.      margin : 0  10px   10px  0;
  64.      display inline ;
  65.     }
  66. .aligncenter {
  67.      display block ;
  68.      margin-left auto ;
  69.      margin-right auto ;
  70.      margin-bottom 10px ;
  71.     }
  72. .alignright {
  73.      float right right ;
  74.      margin : 0 0  10px   10px ;
  75.     }
  76. .alignleft {
  77.      float left ;
  78.      margin : 0  10px   10px  0;
  79.     }

Next, open the functions.php template file of the HotNews Pro theme and add a sentence:

  1. //Background Preview
  2. add_editor_style('/css/editor-style.css');

Third, there is no third. Ha ha, all the transformation is completed!

This function has been integrated in the upcoming official version of HotNews Pro 2.7.

Since the background editor and the foreground editor are in different style frames, if you want to transform other themes, just copy the styles related to the body in the theme style.css and remove the specific selectors. For example, the style code above can also refer to the editor-style.css in the default theme TwentyEleven, The key is to set the width of the body to be the same as the body of your theme.

 

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
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 fifty-two    Visitors forty-three    Author eight
    •  Horse gnawed spinach basket
      Horse gnawed spinach basket one

      I'm a sofa. I'm going to see what Twenty Eleven is like

      •  Brother Qiang
        Brother Qiang four

        The sofa is gone. When will the official version be released?

          •  Robin
            Robin

            @ Brother Qiang It should be done quickly. We should catch up with the three days of the holiday to improve it, because we don't have much time to work at ordinary times

          •  Jinan Decoration
            Jinan Decoration one

            The wp is indeed powerful.. It seems necessary to change

            •  Pekko Wei
              Pekko Wei two

              Don't understand --#

              •  Sichuanese
                Sichuanese six

                Boss, didn't you say there was no official version!

                •  shtion
                  shtion three

                  Every time Brother Bird shares his skills, he is different. Thank you very much for your efforts and permanent support! We look forward to the early completion and release of the official version of 2.7! Wish Brother Bird a happy Mid Autumn Festival!

                  •  Giant Panda
                    Giant Panda five

                    Learned

                    •  ruantoo
                      ruantoo four

                      Use a bird~~~

                      •  Jiujiang Blog
                        Jiujiang Blog two

                        I wish bloggers a happy Mid Autumn Festival. Work is important, blogging is important, and festivals and family reunions are even more important! I wish you and your family a healthy and happy holiday, hehe!

                        •  People who can see the wind
                          People who can see the wind six

                          I wish Brother Bird a happy Mid Autumn Festival, good health, smooth work and happy family!

                          •  Bob
                            Bob five

                            Happy Mid Autumn Festival!

                              •  Robin
                                Robin

                                @ Bob Wish everyone happy every day

                              •  Hefei SEO
                                Hefei SEO four

                                Wish Brother Bird happy every day

                                •  Qianglong
                                  Qianglong three

                                  We look forward to the official release of Bird Brother 2.7..

                                  •  Beijing Art Photography
                                    Beijing Art Photography one

                                    Very good. Learn.

                                    •  Steam turbine
                                      Steam turbine one

                                      The best wordpress I've ever seen

                                      •  Little fish
                                        Little fish four

                                        Mm-hmm. It's very convenient..

                                        •  Jialin
                                          Jialin four

                                          This should be named. I had thought about this function before.

                                          •  Loong
                                            Loong one

                                            How to set the classification at the bottom of the website page to display only the largest classified friendship links? That's also deformed

                                            •  Studio
                                              Studio four

                                              I don't know much about code. I need to learn

                                              •  Grassroots entrepreneurship
                                                Grassroots entrepreneurship three

                                                Waiting for version 2.7 to appear, there is no end to technology
                                                Learned

                                                •  Fuju
                                                  Fuju five

                                                  Brother Bird, let me give you a suggestion on our template. In the cms mode, the current four small color blocks of "green, yellow, blue and orange" in the column have been canceled? Because the overall feeling is that there are too many colors, and a long time of watching will cause great pressure on the vision, which is a bit messy.

                                                  •  Wuxi Stock Training
                                                    Wuxi Stock Training three

                                                    It's quite good!! Learned!!!

                                                    •  Website filing
                                                      Website filing two

                                                      Other themes are not supported

                                                      •  My Mobile Internet
                                                        My Mobile Internet two

                                                        It is said that Microsoft has now released the starter kit in the Marketplace of Windows Phone 7, making it easier and faster to develop WordPress mobile software. I hope that the background management of WordPress will be more powerful in the future

                                                        •  wmtimes
                                                          wmtimes seven

                                                          This is very good. I have collected it.

                                                          •  Mischievous ghost
                                                            Mischievous ghost three

                                                            I'm used to editing in code mode. Preview mode is too resource consuming.

                                                            •  I love talking
                                                              I love talking four

                                                              Hello, Brother Bird, I feel good using your template. My wp postviews plug-in, which records the number of views, makes statistics on a single log. If I refresh the page, the number of views will increase twice. Returning to the home page, he added it again. For example, refresh http://www.52liao8.com/archives/1636.html This article. Online solution, please brother bird.

                                                                •  I love talking
                                                                  I love talking four

                                                                  @ I love talking In addition, this happens in Google Chrome, and other browsers display normally. But your website is normal in Google.

                                                                    •  Robin
                                                                      Robin

                                                                      @ I love talking Count Views From in wp postviews plug-in settings: select Guests Only
                                                                      Don't take a vanity plug-in seriously

                                                                  •  lcr99
                                                                    lcr99 zero

                                                                    Just leave it alone

                                                                    •  If name
                                                                      If name one

                                                                      Let's see the idol again

                                                                      •  The ending actor
                                                                        The ending actor three

                                                                        Yes, but the background is empty automatically. The front desk is empty as usual. Unless the background is empty for nearly 5 words, the front desk is basically empty. Where can I change it to be consistent?

                                                                        •  Ziming
                                                                          Ziming two

                                                                          I feel good when I use Hotnews. At first sight, I knew it was what I wanted.

                                                                          •  Watsons official website
                                                                            Watsons official website five

                                                                            Preview mode feels too resource intensive.

                                                                            •  Handu Clothing House Flagship Store
                                                                              Handu Clothing House Flagship Store zero

                                                                              How awesome! I learned

                                                                              •  soping
                                                                                soping zero

                                                                                Just after seeing such a practical article, I beat my chest and stamped my feet, and I will toss about tonight!

                                                                                •  Taobao discount website
                                                                                  Taobao discount website one

                                                                                  How awesome! I learned

                                                                                  •  ssa
                                                                                    ssa one

                                                                                    Very good blog, we like it. You may be interested in our services. We provide Beijing Fashion Design Course, Beijing Digital Photography Course, and Beijing Web Design and Development Course to help Chinese friends integrate into the international market, which is not only our responsibility, but also our pleasure. If it can help you, we will be very happy. Although we are from France to Beijing, we believe that knowledge and learning have no borders. Thank you webmaster:)

                                                                                    •  Aiko fish
                                                                                      Aiko fish one

                                                                                      I used 2.7 very well! Thanks for your support, Brother Bird!

                                                                                      •  keke
                                                                                        keke one

                                                                                        Hello blogger, the theme itself is indented by 2 spaces in the first line by default, but sometimes it needs to be indented by 2 spaces, so I simply indented the first line by 2 spaces, and deleted text indent: 2em in style.css; Code, but the background editor still displays the first line indented by 2 spaces. I think it should be modified here, so please ask the building owner how to modify it. I try to delete the text indent: 2em above; But it still failed. I still want to ask the blogger. I hope the blogger can find time to answer. Thank you

                                                                                          •  Robin
                                                                                            Robin

                                                                                            @ keke Open the theme editor-style.css, delete text-indent: 2em

                                                                                          •  alexxiaoxie
                                                                                            alexxiaoxie one

                                                                                            Mockingbird has used your theme. The login on the home page is not available, and it has become an invalid connection
                                                                                            Solve it

                                                                                            •  Ferret
                                                                                              Ferret three

                                                                                              What is the specific selector? Please consult the blogger.

                                                                                              •  Xiao Hao
                                                                                                Xiao Hao zero

                                                                                                Brother Bird, background editing of your theme Visual insertion or editing link is not available, only manual input in html<a herf= Can be repaired or provided with the following methods

                                                                                               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