WordPress: Me pehea te Tuhirua i te Waehere Poto Mai i te Kaupapa Matua i roto i to Kaupapa Tamariki, i te Mono Mono Ritenga ranei
Ko te nuinga o o taatau kiritaki he patene kua whakatinanahia ma nga tohu poto kaupapa matua. I patai mai tetahi o o maatau hoa mena ka taea e matou te mahi i etahi mahi aroturuki i runga i nga patene i te mea he tino karanga-ki-mahi (CTA) puta noa i nga waahi. Ko te paatene poto ka whakamahia e matou ka whakaputa aunoa i te paatene pai ma te taapiri i nga karaehe ki te putanga HTML.
Anei te waehere poto hei whakaputa i te paatene hei toro ki taku pae:
[button link="https://martech.zone/partner/dknewmedia/"]Visit DK New Media[/button]
Ka puta mai:
<a href="https://martech.zone/partner/dknewmedia/" class="button blue medium">Visit DK New Media</a>
A koinei te ahua:
Tāpirihia te Aroturuki Takahanga GA4 ki tetahi Waehere Poto
E hiahia ana matou ki te whakahou i te putanga HTML hei taapiri aunoa tātaritanga Google 4 Aroturuki Takahanga ina paohia te paatene:
<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>
I hangaia te paatene poto i roto i to maatau kaupapa matua, no reira kare matou e hiahia ki te whakarereke i to maatau kaupapa taketake hei whakauru i te huringa na te mea ka ngaro aua huringa mena ka whakahouhia e matou te kaupapa. He otinga, ahakoa! Ko te WordPress API ka taea e koe te tango i tetahi waehere poto ma te whakamahi i te remove_shortcode
mahi!
Ka taea tenei ki te kaupapa o to tamaiti functions.php
kōnae, ma te whakamahi ranei i te waehere i roto i tetahi mahi ritenga. Ka tohutohu ahau ki te tuku i o kupu poto katoa e pa ana ki te ihirangi ki roto i te mono ritenga, kaua ki te konae kaupapa. Utauta rite MAORI kaua e tukuna he waehere poto ki nga kaupapa.
Tuhia he Waehere Poto I roto i te Kaupapa Tamariki
I roto i te kaupapa tamaiti, ka taea e koe te tango i te waehere poto me te whakakapi ki ta maatau mahi tohu poto hou. Me rapu koe i to waehere kaupapa matua kia kitea ai te mahi (ka karangahia button_function_in_parent_theme
kei raro) ka hanga te waehere poto ka taea e koe te whakamahi i roto i tenei waahanga 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' );
}
Inaianei, ka taea e koe te taapiri i to mahi tohu poto hou me te whakahou me te aroturuki takahanga 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');
Tuhia he Waehere Poto ma te whakamahi i te monomai ritenga
Ka tūtohu ahau ki te hanga i tetahi mono motuhake mo to papaanga e whakauru ana i o waehere poto katoa, tae noa ki nga mea kei roto i to kaupapa. Hei mahi i tenei:
- Waihangahia he kōpaki he ingoa motuhake. Hei tauira, ko to matou ingoa mtz-waehere poto.
- I roto i taua konae, taapirihia he shortcodes.php kōnae. (Ka taea e koe te whakaingoa i nga mea katoa e hiahia ana koe)
- I roto i te konae shortcodes.php, ka taea e koe te taapiri i te waehere i runga ake nei hei taapiri mo nga korero mono ka whakaatuhia ki to wharangi mono:
<?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;
}
- Ka taea e koe te tango me te taapiri i nga waehere poto maha i roto i te mahi i runga ake nei mena he nui ake i te kotahi te waehere poto e hiahia ana koe ki te whakakapi ma te whakamahi i to monohiko ritenga.
- Putuhia te kōpaki, ka taea e koe te tuku me te whakahohe i te mono ma to tahua monomai WordPress.