Created
August 11, 2015 15:58
-
-
Save jsoningram/fa93ba1e8f43a57d06a4 to your computer and use it in GitHub Desktop.
WordPress helper functions
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 | |
// if CabbageCMS, include Mobile Detect class | |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
if ( is_plugin_active( 'cabbagecms/cabbage-cms.php' ) ) { | |
include ABSPATH . 'wp-content/plugins/cabbagecms/_/inc/mobile-detect/Mobile_Detect.php'; | |
} | |
// Put stuff in <head> | |
function header_inject() { ?> | |
<?php } | |
// Add hook for admin <head></head> | |
add_action('admin_head', 'header_inject'); | |
// Add hook for front-end <head></head> | |
add_action('wp_head', 'header_inject'); | |
// Put stuff in the footer | |
function footer_inject() { ?> | |
<?php } add_action('wp_footer', 'footer_inject'); | |
// Remove Open Sans that WP adds from frontend | |
if (!function_exists('remove_wp_open_sans')) : | |
function remove_wp_open_sans() { | |
wp_deregister_style( 'open-sans' ); | |
wp_register_style( 'open-sans', false ); | |
} add_action('wp_enqueue_scripts', 'remove_wp_open_sans'); | |
endif; | |
// remove query string after static resources. | |
function _remove_script_version( $src ){ | |
$parts = explode( '?ver', $src ); | |
return $parts[0]; | |
} | |
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 ); | |
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 ); | |
// get domain.com/blog/THESLUG/ | |
function the_slug($echo=true){ // pass false to return | |
$slug = basename(get_permalink()); | |
do_action('before_slug', $slug); | |
$slug = apply_filters('slug_filter', $slug); | |
if( $echo ) echo $slug; | |
do_action('after_slug', $slug); | |
return $slug; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment