Created
April 6, 2026 18:20
-
-
Save cdevroe/ac152b9de66b9766fbbe0e1b3ae055d7 to your computer and use it in GitHub Desktop.
Enable Hubbub Pro's Pinterest Image Hover button on select pages even with the tool off
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Enable Grow's Pinterest Image Hover button only on specific page slugs. | |
| * | |
| * Replace the slugs below with your allowed pages. | |
| * Examples: | |
| * - 'about' | |
| * - 'contact' | |
| * - 'recipes/breakfast' (for nested pages) | |
| */ | |
| /** | |
| * Return true when the current front-end request should have the Pinterest hover button. | |
| */ | |
| function np_enable_grow_pinterest_hover_for_selected_slugs() { | |
| if ( is_admin() || ! is_singular() ) { | |
| return false; | |
| } | |
| $post = get_queried_object(); | |
| if ( ! ( $post instanceof WP_Post ) ) { | |
| return false; | |
| } | |
| $allowed_slugs = array( | |
| 'about', | |
| 'contact', | |
| 'pricing', | |
| // 'parent-page/child-page', | |
| ); | |
| $allowed_slugs = array_map( 'sanitize_title', $allowed_slugs ); | |
| $candidate_slugs = array_filter( | |
| array( | |
| $post->post_name, | |
| get_page_uri( $post->ID ), // supports hierarchical page paths like parent/child | |
| ) | |
| ); | |
| foreach ( $candidate_slugs as $slug ) { | |
| if ( in_array( sanitize_title( $slug ), $allowed_slugs, true ) ) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| /** | |
| * Pretend the Pinterest hover tool is active only on selected pages. | |
| */ | |
| add_filter( 'mv_grow_setting_dpsp_active_tools', function( $active_tools ) { | |
| if ( ! is_array( $active_tools ) ) { | |
| $active_tools = array(); | |
| } | |
| if ( np_enable_grow_pinterest_hover_for_selected_slugs() && ! in_array( 'share_images', $active_tools, true ) ) { | |
| $active_tools[] = 'share_images'; | |
| } | |
| return $active_tools; | |
| } ); | |
| /** | |
| * Make sure Grow allows the current post type on those selected pages. | |
| */ | |
| add_filter( 'mv_grow_setting_dpsp_pinterest_share_images_setting', function( $settings ) { | |
| if ( ! np_enable_grow_pinterest_hover_for_selected_slugs() ) { | |
| return $settings; | |
| } | |
| if ( ! is_array( $settings ) ) { | |
| $settings = array(); | |
| } | |
| $post = get_queried_object(); | |
| if ( ! ( $post instanceof WP_Post ) ) { | |
| return $settings; | |
| } | |
| if ( empty( $settings['share_image_post_type_display'] ) || ! is_array( $settings['share_image_post_type_display'] ) ) { | |
| $settings['share_image_post_type_display'] = array(); | |
| } | |
| if ( ! in_array( $post->post_type, $settings['share_image_post_type_display'], true ) ) { | |
| $settings['share_image_post_type_display'][] = $post->post_type; | |
| } | |
| return $settings; | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment