Skip to content

Instantly share code, notes, and snippets.

@dharmeshtops
dharmeshtops / wp_code_context.php
Created July 25, 2017 08:40 — forked from mrbobbybryant/wp_code_context.php
Allows you to dynamically determine if your code is being used in a plugin or a theme
<?php
function wp_code_context() {
$theme = strpos( __DIR__, 'themes' );
return ( $theme ) ? 'theme' : 'plugin';
}
function get_directory_by_context() {
$context = wp_code_context();
switch( $context ) {
case 'theme':
$local_dir = get_template_directory();
@dharmeshtops
dharmeshtops / gist:b60569f9d9106f16cc58845dba1482da
Created July 25, 2017 08:39 — forked from mrbobbybryant/gist:3f5ec4f224ad8ca8cd06
Adding a Google Analytics Link to the Wordpress Dashboard
<?php
function dwwp_add_google_link() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'id' => 'google_analytics',
'title' => 'Google Analytics',
'href' => 'http://google.com/analytics/'
) );