Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* move the main settings page for Yoast Google Analytics
* from it's own parent menu into a submenu page in either
* the Yoast SEO menu or in the general settings
*
* @return null
*/
function rkv_yoast_ga_menu() {
// check for the defined path in the event that the plugin
// has been removed
if ( ! defined( 'GAWP_PATH' ) ) {
return;
}
// first remove the top level menu item
remove_menu_page( 'yst_ga_dashboard' );
// check for Yoast SEO plugin first
// and if present, add the item there
if ( function_exists( 'wpseo_auto_load' ) ) {
add_submenu_page( 'wpseo_dashboard', __( 'Google Analytics', 'google-analytics-for-wordpress' ), __( 'Google Analytics', 'google-analytics-for-wordpress' ), 'manage_options', 'yst_ga_settings', 'rkv_yoast_ga_page' );
} else {
// Yoast SEO not installed, just put it into main settings
add_options_page( __( 'Yoast Google Analytics', 'google-analytics-for-wordpress' ), __( 'Yoast Google Analytics', 'google-analytics-for-wordpress' ), 'manage_options', 'admin.php?page=yst_ga_settings', 'rkv_yoast_ga_page' );
}
}
add_action( 'admin_menu', 'rkv_yoast_ga_menu', 999 );
/**
* call the files required for the Yoast GA page to
* render properly
* @return [type] [description]
*/
function rkv_yoast_ga_page() {
// check for the defined path in the event that the plugin
// has been removed
if ( ! defined( 'GAWP_PATH' ) ) {
return;
}
// load our two files
require_once( GAWP_PATH . 'admin/class-admin-ga-js.php' );
require_once( GAWP_PATH . 'admin/pages/settings.php' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment