簡體   English   中英

引號和撇號未顯示在PHP中

[英]Quotation marks and apostrophes not displaying in PHP

我正在嘗試將Google Analytics(分析)的onclick屬性附加到wordpress導航菜單項。

add_filter( 'nav_menu_link_attributes', 'wpse121123_contact_menu_atts', 10, 3 );
function wpse121123_contact_menu_atts( $atts, $item, $args )
{
  // The ID of the target menu item
  $menu_target = 6384;

  $mystring = '\'http://example.com/your-link\'';

  // inspect $item
  if ($item->ID == $menu_target) {
    $atts['onclick'] = 'return gtag_report_conversion(' . htmlentities($mystring, ENT_NOQUOTES) . ');';
  }
  return $atts;
}

我已經嘗試過ENT_QUOTES,ENT_NOQUOTES,使用斜線轉義,使用單引號和雙引號,並帶有和不帶有htmlentities()來轉義,但是HTML始終輸出HTML字符,如下所示。

<a title="link" href="#" class="nav-link" onclick="return gtag_report_conversion(&#039;http://example.com/your-link&#039;);">Link</a>

如何確保按照以下GA文檔的說明進行顯示-即,URL用單引號引起來。

<a title="link" href="#" class="nav-link" onclick="return gtag_report_conversion('http://example.com/your-link');">Link</a>

非常感謝。

這不是我一直在尋找的答案,但是我找到了jQuery的解決方法。

jQuery('#menu-item-6384 > a').attr("onclick", "return gtag_report_conversion('https://www.mylink.com/conversion/');");

消除所有帶有特殊字符的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM