Отключаем удаление пустых span тегов в визуальном редакторе (WordPress)

1 Звезда2 Звезды3 Звезды4 Звезды5 Звезд (Пока оценок нет)
Загрузка...

Собственно для чего это. Если надо разместить, к примеру, микроразметку в визуальном редакторе, то после ставок кода


<span itemprop="streetAddress">номер дома, улица</span>
<span itemprop="postalCode">почтовый индекс</span>
<span itemprop="addressLocality">город, страна</span>

на выходе получим

номер дома, улица
почтовый индекс
город, страна

то есть, редактор сделал валидацию кода и очистил, по его мнению лишний код, а нам такое не нужно.
Как с этим бороться

Вставляем в файл функции темы (functions.php), следующий код


function my_adds_alls_elements($init) {
  if(current_user_can('unfiltered_html')) {
    $init['extended_valid_elements'] = 'span[*],div[*]';
  }
  return $init;
}
add_filter('tiny_mce_before_init', 'my_adds_alls_elements', 20);

В данном случае убираю валидацию с тегов span и div.

div так же очищается если не отключить валидацию, а он часто нужен для микроразметки

Пример

номер дома, улица
почтовый индекс
город, страна

Использую классический редактор

18 комментариев

  • Ronnie

    Appreciating the hard work you put into your website and detailed information you provide.
    It’s great to come across a blog every once in a while that isn’t
    the same old rehashed information. Wonderful read!
    I’ve bookmarked your site and I’m adding your RSS feeds to my Google account.

  • minecraft

    This website truly has all of the information I needed about this subject and didn’t know
    who to ask.

  • minecraft

    Pretty! This has been an extremely wonderful
    post. Many thanks for supplying this information.

  • minecraft

    Simply desire to say your article is as astounding. The clarity
    in your put up is just great and i can suppose you are a
    professional in this subject. Well with your permission allow me to grasp your RSS feed to stay up to date with
    drawing close post. Thanks one million and please
    continue the rewarding work.

  • minecraft

    At this time it looks like Movable Type is the preferred blogging
    platform out there right now. (from what I’ve read) Is that what you’re using on your blog?

  • tinyurl.com

    Very nice post. I just stumbled upon your weblog and wished to say that I’ve truly
    enjoyed surfing around your blog posts. After all I will be subscribing to your rss
    feed and I hope you write again very soon!

  • minecraft

    Howdy are using WordPress for your blog platform?
    I’m new to the blog world but I’m trying to get started and set up my own. Do you need any coding expertise to make your own blog?
    Any help would be greatly appreciated!

  • minecraft

    I was more than happy to uncover this site. I wanted to thank you
    for ones time just for this fantastic read!! I definitely appreciated every bit of it and
    I have you book-marked to check out new stuff on your web site.

  • how to get help in windows 10

    Thanks for finally talking about >Отключаем удаление пустых
    span тегов в визуальном редакторе (WordPress) — Грабли <Loved it!

  • Stephenheani

    I apologise, but, in my opinion, you are not right. I can defend the position. Write to me in PM, we will communicate.

    • admin

      Данный код — рабочий. Я использовал вордпресс 5.2.2 и классический редактор вместо нового блочно редактора.
      Для демонстрации, что все-таки код рабочий, на странице разместил в примере кусок со span, где прописал атрибуты, и добавил в эту функцию в функции темы.
      Возможно у вас есть другой вариант решения данной проблемы

  • MattieExtic

    Поздравляю, мне кажется это блестящая мысль

  • oprolevorter

    Some times its a pain in the ass to read what website owners wrote but this website is really user friendly! .

  • plenty of fish dating site

    of course like your web-site however you need to test the spelling on several of your posts.
    Many of them are rife with spelling issues and I find it
    very bothersome to inform the truth nevertheless I will certainly come back again.

  • that coconut oil

    Woah! I’m really digging the template/theme of this
    blog. It’s simple, yet effective. A lot of times it’s very difficult to
    get that «perfect balance» between usability and visual
    appeal. I must say you’ve done a very good job with this.
    In addition, the blog loads very fast for me on Firefox.
    Exceptional Blog!

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *