Das Plugin AMP for WordPress von Automattic bereitet Beiträge für die optimierte Darstellung von mobilen Suchergebnissen bei Google auf.
Die Navigation geht dabei allerdings verloren. Das ist in Bezug auf Impressums- und Datenschutzerklärungs-Pflicht nicht zulässig. Nachfolgendes Mini-Plugin registriert eine neue Menüposition für den AMP-Footer und setzt diesen nachdem er mit einem Menü verknüpft wurde im Footer von AMP-Seiten ein.
<?php
/**
* Plugin Name: GDPR Compliant AMP
* Description: Ads a menu location to the footer of AMP plugin from automattic. Just activate, got to menu settings and add necessary items to a new custom menu located in AMP Footer
* Author: Gabriele Laesser
* Author URI: https://blog.webentwicklerin.at/
* Plugin URI: https://webentwicklerin.at/
* Version: 1.0.0
*/
defined( 'ABSPATH' ) or die();
/**
* Hook to register a new menu
*/
add_action( 'init', 'gdpr_amp_footer_menu' );
/**
* Hook to add content to the AMP footer
*/
add_action( 'amp_post_template_footer', 'gdpr_amp_footer_action' );
/**
* register menu for AMP footer
*/
function gdpr_amp_footer_menu() {
register_nav_menu( 'amp_footer', __( 'AMP Footer Menu', 'gdpr-compliant-amp' ) );
}
/**
* diplay the menu in AMP footer
*/
function gdpr_amp_footer_action() {
$menus = get_nav_menu_locations();
$pages = wp_get_nav_menu_items($menus['amp_footer']);
if ( !$pages ) return;
echo '<ul class="amp-menu">';
foreach ( $pages as $page ) {
printf( '<li><a href="%1$s">%2$s</a></li>', esc_url($page->url) , esc_html($page->title) );
}
echo '</ul>';
}
Schreibe einen Kommentar