New Facebook like button HTML validation

前端 未结 15 1981
抹茶落季
抹茶落季 2020-12-02 11:34

After adding the new facebook like button on my page, it\'s no longer validates using XHTML strict standard. The two errors I come across are:

  1. All of the
15条回答
  •  感情败类
    2020-12-02 12:06

    Here is the pure solution (trick) for making ANY tags or not recognized codes validated!

    I use smarty as a template engine, but it can be done the same way if you don't!

    I thought up more a trick rather than a solution (because there is no one so far) and just made W3C Validator to pass validation simply by NOT showing those meta strings to it.

    When Validator referring to my page, using PHP, I don't render the content that is not recognized by W3C Validator. I simply do this by extracting headers' information that is sent by W3C Validator, which is user-agent and which is W3C_Validator/version.

    1. Create PHP function and assign it to Smarty:

      function User_Agent_Check($user_agent) {
        $user_agent_check = strpos($_SERVER['HTTP_USER_AGENT'], $user_agent);
          if ($user_agent_check === false) {
              return false;
          } else {
              return true;
          }
      }
      
    2. Then let's check the user agent:

      if (User_Agent_Check("W3C_Validator")) {
         $smarty->assign('W3C', "1");
       } else {
         $smarty->assign('W3C', "0");
      }
      
    3. Then in Smarty template you use (if you don't use Smarty just 'echo' the content with PHP):

      {if $W3C == 0}
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
      {/if}
      

    When Validator tries to check your page those meta tags are just not output to the page! When any other user agent is seeing your page then those codes are just output as usual! You can do this for Facebook Like Button or for any OG Metatags - actually for anything else.

    It's happened to be zeitgeist right solution for me!

提交回复
热议问题