将 HTML 换成 AMP 页面
Exchange HTML in for AMP Pages
有没有办法在 AMP 页面中更改 HTML?示例:
每 <span class="example1">...</span>
至 <a href="example1">...</a>
或者更好的是,将 Wordpress 中的特定简码更改为 <a href="example1">...</a>
?
我找到了切换短代码的解决方案:
// AMP change thrive-shortcode to landingpage link
function add_shortcode_amp($content) {
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
/// Define shortcode-name
$mb_shortc = 'thrive_2step';
/// Define Mappings (thrive_2step id => Target URL for links in AMP)
$ampMappings = array(
"17503" => 'https://www.test.de/schreibtisch-workout-2',
"17505" => 'https://www.test.de/merkmale-arbeitsplatz-kostenlos',
"17506" => 'https://www.test.de/hoehenverstellbarer-schreibtisch-rentenverischerung-antrag');
/// Init Regex arrays
$mb_rexp = array();
$subst = array();
foreach ($ampMappings as $key => $value) {
$mb_rexp[] = '/\[('.$mb_shortc.').*?.id=[\'"]'.$key.'[\'"].*?\](.*?)\[\/\]?/';
$subst[] = '<a href="'.$value.'"></a>';
}
/// Process Content
return preg_replace($mb_rexp, $subst, $content);
}
return $content;
}
add_filter( 'the_content', 'add_shortcode_amp', 6);
function mbtest_hello_world() {
return '<a>Hello World</a>';
}
add_shortcode('AMPTEST', 'mbtest_hello_world');
function shortcode_switch4amp( $atts) {
extract( shortcode_atts( array(
'regular' => 'regular',
'amp' => 'amp'
), $atts ) );
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
return do_shortcode(str_replace(array("{","}"), array("[","]"),$amp));
} else {
return do_shortcode(str_replace(array("{","}"), array("[","]"), $regular));
}
}
add_shortcode('switch4amp', 'shortcode_switch4amp');
有没有办法在 AMP 页面中更改 HTML?示例:
每 <span class="example1">...</span>
至 <a href="example1">...</a>
或者更好的是,将 Wordpress 中的特定简码更改为 <a href="example1">...</a>
?
我找到了切换短代码的解决方案:
// AMP change thrive-shortcode to landingpage link
function add_shortcode_amp($content) {
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
/// Define shortcode-name
$mb_shortc = 'thrive_2step';
/// Define Mappings (thrive_2step id => Target URL for links in AMP)
$ampMappings = array(
"17503" => 'https://www.test.de/schreibtisch-workout-2',
"17505" => 'https://www.test.de/merkmale-arbeitsplatz-kostenlos',
"17506" => 'https://www.test.de/hoehenverstellbarer-schreibtisch-rentenverischerung-antrag');
/// Init Regex arrays
$mb_rexp = array();
$subst = array();
foreach ($ampMappings as $key => $value) {
$mb_rexp[] = '/\[('.$mb_shortc.').*?.id=[\'"]'.$key.'[\'"].*?\](.*?)\[\/\]?/';
$subst[] = '<a href="'.$value.'"></a>';
}
/// Process Content
return preg_replace($mb_rexp, $subst, $content);
}
return $content;
}
add_filter( 'the_content', 'add_shortcode_amp', 6);
function mbtest_hello_world() {
return '<a>Hello World</a>';
}
add_shortcode('AMPTEST', 'mbtest_hello_world');
function shortcode_switch4amp( $atts) {
extract( shortcode_atts( array(
'regular' => 'regular',
'amp' => 'amp'
), $atts ) );
if (function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) {
return do_shortcode(str_replace(array("{","}"), array("[","]"),$amp));
} else {
return do_shortcode(str_replace(array("{","}"), array("[","]"), $regular));
}
}
add_shortcode('switch4amp', 'shortcode_switch4amp');