Plugin Directory

Changeset 3221823


Ignore:
Timestamp:
01/13/2025 09:27:55 PM (15 months ago)
Author:
skyword
Message:

Shortcode: Better handling of tracking script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skyword-plugin/tags/2.5.3/php/class-skyword-shortcode.php

    r3220301 r3221823  
    55    function __construct() {
    66        add_shortcode('cf', array($this, 'customfields_shortcode'));
    7         add_shortcode('skyword_tracking', array(
     7        add_shortcode('skyword_tracking_tag', array(
    88            $this,
    9             'skyword_tracking'
     9            'skyword_tracking_tag'
    1010        ));
    1111        add_shortcode('skyword_anonymous_tracking', array(
     
    2828     * Append the standard Skyword tracking tag
    2929     */
    30     function skyword_tracking($atts) {
     30    function skyword_tracking_tag($atts) {
    3131        if ( isset( $atts['id'] ) )
    3232            $id = $atts['id'];
    3333        else
    3434            $id = get_post_meta(get_the_ID(), 'skyword_content_id', true);
    35         return "<script async='' type='text/javascript' src='//tracking.skyword.com/tracker.js?contentId={$id}'></script>";
     35        return wp_enqueue_script('skyword-tracking');
    3636    }
    3737
     
    4444        else
    4545            $id = get_post_meta(get_the_ID(), 'skyword_content_id', true);
    46         return "<script async='' type='text/javascript' src='//tracking.skyword.com/tracker.js?contentId={$id}&anonymize=yes'></script>";
     46        return wp_enqueue_script('skyword-anonymous-tracking');
    4747    }
    4848
     
    9595}
    9696
     97function register_tracking_scripts() {
     98    wp_register_script( 'skyword-tracking', '//tracking.skyword.com/tracker.js');
     99    wp_register_script( 'skyword-anonymous-tracking', '//tracking.skyword.com/tracker.js?anonymize=yes');
     100}
     101
     102add_action( 'wp_enqueue_scripts', 'register_tracking_scripts' );
     103
    97104global $custom_shortcodes;
    98105$custom_shortcodes = new Skyword_Shortcode;
Note: See TracChangeset for help on using the changeset viewer.