Litlhahlobo le TekoMarketing Content

WordPress: Mokhoa oa ho Ngola Shortcode ho Tloha Sehloohong sa Batsoali ho Theme ea Ngoana oa Hao kapa plugin ea tloaelo

Bareki ba rona ba bangata ba na le likonopo tse kentsoeng tšebetsong ka li-shortcode tsa sehlooho sa motsoali. E mong oa balekane ba rona o ile a botsa hore na re ka etsa tracking ea ketsahalo ka likonopo kaha e ne e le pitso e ntle ea ho etsa liketso (CTA) libakeng tsohle. Shortcode ea konopo eo re e sebelisang e hlahisa konopo e ntle ka ho eketsa litlelase ho sephetho HTML.

Mona ke shortcode ea ho hlahisa konopo ho etela sebaka sa ka sa marang-rang:

[button link="https://martech.zone/partner/dknewmedia/"]Visit DK New Media[/button]

Seo se hlahisa:

<a href="https://martech.zone/partner/dknewmedia/" class="button blue medium">Visit DK New Media</a>

'Me mona ke kamoo e shebahalang kateng:

hape u ba etele DK New Media

Eketsa Tracking ea Ketsahalo ea GA4 ho Shortcode ea Button

Re batla ho nchafatsa tlhahiso ea HTML hore re e kenye ka bo eona Analytics Google 4 Tracking ea Ketsahalo ha konopo e tobetse:

<a href="https://martech.zone/partner/dknewmedia/" class="button blue medium" onclick="gtag('event', 'click', {'event_category': 'button', 'event_label': 'Visit DK New Media'});">Visit DK New Media</a>

Shortcode ea konopo e entsoe ho rona sehlooho sa motsoali, kahoo ha re batle ho fetola sehlooho sa rona sa mantlha hore se lumellane le phetoho kaha liphetoho tseo li ka lahleha haeba re ka ntlafatsa sehlooho. Leha ho le joalo, tharollo e teng! WordPress API e o nolofalletsa ho tlosa shortcode ho sebelisa remove_shortcode tshebetso!

Sena se ka etsoa molemong oa ngoana oa hau functions.php faele kapa ka ho sebelisa khoutu ts'ebetsong ea tloaelo. Ke eletsa ho kenya li-shortcode tsohle tsa hau tse amanang le litaba ka har'a plugin ea tloaelo ho fapana le faele ea sehlooho. Lisebelisoa tse kang Amp se ke oa fana ka li-shortcodes ho lihlooho.

Ngola Shortcode ho Theme ea Ngoana

Sehloohong sa ngoana, o ka tlosa shortcode mme o e nkele sebaka ka ts'ebetso ea rona e ncha ea shortcode. U tla hloka ho batla khoutu ea sehlooho sa motsoali oa hau ho fumana ts'ebetso (e bitsoang button_function_in_parent_theme ka tlase) e etsang shortcode ebe u ka e sebelisa ho snippet ena ho functions.php:

add_action( 'after_setup_theme', 'update_button_shortcode' );

function update_button_shortcode() {
    remove_shortcode( 'button_function_in_parent_theme' );
    add_shortcode( 'button', 'new_button_shortcode' );
}

Joale, o ka eketsa ts'ebetso ea hau e ncha le e ntlafalitsoeng ea shortcode ka ho latela ketsahalo ea GA4:

function new_button_shortcode($atts, $content = null) {
    // Extract shortcode attributes
    $attributes = shortcode_atts(
        array(
            'link' => '#', // Default value if 'link' is not provided
        ), 
        $atts
    );

    $url = esc_url($attributes['link']);
    $text = esc_html($content);

    // Generate the HTML output
    $html = '<a href="' . $url . '" class="button blue medium" onclick="gtag(\'event\', \'click\', {\'event_category\': \'button\', \'event_label\': \'' . $text . '\'});">' . $text . '</a>';

    return $html;
}

// Register the shortcode
add_shortcode('button', 'new_button_shortcode');

Ngola Shortcode ka ho Sebelisa Plugin e Tloaelehileng

Ke khothaletsa ho aha plugin e ikhethileng bakeng sa sebaka sa hau sa marang-rang e kenyelletsang li-shortcode tsa hau kaofela, esita le tse ka har'a sehlooho sa hau. Ho etsa sena:

  1. Etsa sephutheli se nang le lebitso le ikhethileng. Ka mohlala, ea rona e bitsoa mtz-shortcodes.
  2. Ka har'a faele eo, eketsa a shortcodes.php faele. (O ka e reha eng kapa eng eo o e batlang)
  3. Ka har'a faele ea shortcodes.php, u ka eketsa khoutu e ka holimo ho phaella boitsebisong ba plugin bo tla hlaha leqepheng la hau la li-plugins:
<?php
/*
Plugin Name: Martech Zone Shortcodes
Description: Shortcodes for Martech Zone. This way they work with AMP.
Version: 1.0.0
Author: Douglas Karr
Author URI: https://dknewmedia.com
*/

function update_shortcodes() {
    remove_shortcode( 'button_function_in_parent_theme' );
    add_shortcode( 'button', 'new_button_shortcode' );
}
add_action( 'init', 'update_shortcodes' );

function new_button_shortcode($atts, $content = null) {
    // Extract shortcode attributes
    $attributes = shortcode_atts(
        array(
            'link' => '', // Default value if 'link' is not provided
        ), 
        $atts
    );

    $url = esc_url($attributes['link']);
    $text = esc_html($content);

    // Generate the HTML output
    $html = '<a href="' . $url . '" class="button blue medium" onclick="gtag(\'event\', \'click\', {\'event_category\': \'button\', \'event_label\': \'' . $text . '\'});">' . $text . '</a>';

    return $html;
}
  1. U ka tlosa le ho kenya li-shortcode tse ngata tšebetsong e kaholimo haeba u na le li-shortcode tse fetang bonngoe tseo u ka ratang ho li fetola u sebelisa plugin ea hau ea tloaelo.
  2. Tlosa foldara, 'me joale u ka kenya le ho kenya plugin ka har'a menyu ea li-plugins tsa WordPress.

Douglas Karr

Douglas Karr ke CMO ea Bula LITLHAKISO le mothehi oa Martech Zone. Douglas o thusitse batho ba bangata ba atlehileng ho qala ka MarTech, o thusitse boitelong bo nepahetseng ba chelete e fetang $5 bilione ho reka le matsete a Martech, mme o ntse a tsoela pele ho thusa lik'hamphani ho kenya ts'ebetsong le ho iketsetsa maano a bona a ho rekisa le ho bapatsa. Douglas ke setsebi le sebui sa MarTech se tsebahalang lefatšeng ka bophara. Douglas hape ke sengoli se hatisitsoeng sa tataiso ea Dummie le buka ea boetapele ba khoebo.

Related Articles

Konopo ea holimo
Close

Adblock e fumanwe

Martech Zone e khona ho u fa litaba tsena ntle ho tefo hobane re etsa chelete sebakeng sa rona sa marang-rang ka lekeno la lipapatso, likhokahano tsa kopanelo le lithuso tsa lichelete. Re ka thabela ha o ka tlosa se thibelang lipapatso ha u ntse u sheba sebaka sa rona sa marang-rang.