googlechromelabs / wp-third-parties
This package is a collection of classes and utilities that can be used to efficiently load third-party libraries into your WordPress application.
Requires
- php: >=7.2
- googlechromelabs/third-party-capital: ^3.0.0
Requires (Dev)
- brain/monkey: ^2.6
- dealerdirect/phpcodesniffer-composer-installer: ^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0
- mockery/mockery: ^1.4
- phpcompatibility/php-compatibility: ^9.3
- phpmd/phpmd: ^2.9
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.10
- slevomat/coding-standard: ^8.9
- szepeviktor/phpstan-wordpress: ^1.1
- wp-coding-standards/wpcs: ^3.0.0
- wp-phpunit/wp-phpunit: ^6.1
- yoast/phpunit-polyfills: ^1.0
README
This package is a collection of classes and utilities that can be used to efficiently load third-party libraries into your WordPress application.
It relies on the platform agnostic solution from Third Party Capital.
Installation
You can include this package in your WordPress project using Composer:
composer require googlechromelabs/wp-third-parties:^1.0
Usage
Google Analytics
$ga = new Google_Chrome_Labs\WP_Third_Parties\Third_Parties\Google_Analytics( array( 'id' => 'G-...', // Replace this with your actual Google Analytics ID. ) ); // Add hooks to enqueue assets. add_action( 'wp_loaded', array( $ga, 'add_hooks' ) );
See the Google Analytics JSON schema for the full list of supported arguments.
Google Tag Manager
$gtm = new Google_Chrome_Labs\WP_Third_Parties\Third_Parties\Google_Tag_Manager( array( 'id' => 'GTM-...', // Replace this with your actual Google Tag Manager ID. ) ); // Add hooks to enqueue assets. add_action( 'wp_loaded', array( $gtm, 'add_hooks' ) );
See the Google Tag Manager JSON schema for the full list of supported arguments.
Google Maps Embed
$gme = new Google_Chrome_Labs\WP_Third_Parties\Third_Parties\Google_Maps_Embed( array( 'mode' => '...', // Provide this and other parameters like 'key', 'q', 'center', etc. ) ); // No assets need to be enqueued for a Google Maps Embed. // To actually render the Google Maps Embed, use this. echo $gme->get_html();
See the Google Maps Embed JSON schema for the full list of supported arguments.
YouTube Embed
$yte = new Google_Chrome_Labs\WP_Third_Parties\Third_Parties\YouTube_Embed( array( 'videoid' => '...', // Replace this with your actual YouTube video ID. ) ); // Add hooks to enqueue assets. add_action( 'wp_loaded', array( $yte, 'add_hooks' ) ); // To actually render the YouTube Embed, use this. echo $yte->get_html();
See the YouTube Embed JSON schema for the full list of supported arguments.