Archived topic
GP Premium override functions in child theme
1 reply · Started by dprophitjr on January 24, 2018
I tried adding this to my child theme functions:
if ( ! function_exists( 'generate_setup' ) ) {
add_action( 'after_setup_theme', 'generate_setup' );
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* @since 0.1
*/
function generate_setup() {
// Make theme available for translation.
load_child_theme_textdomain( 'yada', get_stylesheet_directory() . '/languages' );
add_action( 'wp_loaded', 'remove_my_parent_theme_function' );
function remove_my_parent_theme_function() {
remove_action( 'after_setup_theme', 'generate_article_schema' );
remove_action( 'after_setup_theme', 'generate_body_itemtype' );
remove_action( 'after_setup_theme', 'generate_clone_sidebar_navigation' );
}
That didn't remove the functions to allow me to include modified functions with same name. I need to also modify some premium plugin functions.
Hi Denver,
That's not quite how it works.
I typically don't suggest overwriting functions, as you may run into issues with updates in the future. However, if you need to, the function needs to be wrapped in a function_exists() wrapper.
If it is, you need include the entire function along with the wrapper, like this:
if ( ! function_exists( 'generate_article_schema' ) ) {
/**
* Figure out which schema tags to apply to the <article> element
* The function determines the itemtype: generate_article_schema( 'BlogPosting' )
* @since 1.3.15
*/
function generate_article_schema( $type = 'CreativeWork' ) {
// Get the itemtype
$itemtype = esc_html( apply_filters( 'generate_article_itemtype', $type ) );
// Print the results
echo "itemtype='http://schema.org/$itemtype' itemscope='itemscope'"; // WPCS: XSS ok, sanitization ok.
}
}
Then make your changes.
generate_clone_sidebar_navigation() doesn't have a wrapper, as we're moving away from them completely.
Instead, you would do this:
remove_action( 'wp_footer', 'generate_clone_sidebar_navigation' );
add_action( 'wp_footer', 'tu_clone_sidebar_navigation' );
function tu_clone_sidebar_navigation() {
// Your custom function
}