Skip to content

Instantly share code, notes, and snippets.

View jimboobrien's full-sized avatar

Jimobrien jimboobrien

View GitHub Profile
@jimboobrien
jimboobrien / rss-shortcode.php
Created September 20, 2017 23:32 — forked from wpscholar/rss-shortcode.php
WordPress shortcode allows you to create content that is visible only in your RSS feeds.
<?php
/**
* WordPress shortcode allows you to create content that is visible only in your RSS feeds.
*
* Example: [feedonly]Dear RSS readers...[/feedonly]
*/
function feedonly_shortcode( $atts, $content = null) {
if (!is_feed()) return "";
return $content;
@jimboobrien
jimboobrien / append-nav-items.php
Created September 20, 2017 23:30 — forked from wpscholar/append-nav-items.php
Add a custom link to the end of a menu that uses the wp_nav_menu() function
<?php
/**
* Add a custom link to the end of a specific menu that uses the wp_nav_menu() function
*/
add_filter('wp_nav_menu_items', 'add_admin_link', 10, 2);
function add_admin_link($items, $args){
if( $args->theme_location == 'footer_menu' ){
$items .= '<li><a title="Admin" href="'. esc_url( admin_url() ) .'">' . __( 'Admin' ) . '</a></li>';
}
@jimboobrien
jimboobrien / generate-list.php
Created September 20, 2017 23:30 — forked from wpscholar/generate-list.php
Take a multi-dimensional array in $_POST format and convert into an unordered list.
<?php
/**
*
* Take a multi-dimensional array in $_POST format and convert into an unordered list.
*
* @param $data
* @param array $args
* @return string
*/
@jimboobrien
jimboobrien / wp-redirect.php
Created September 20, 2017 23:30 — forked from wpscholar/wp-redirect.php
WordPress function for redirecting users on login based on user role
<?php
/**
* WordPress function for redirecting users on login based on user role
*/
function my_login_redirect( $url, $request, $user ){
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if( $user->has_cap( 'administrator' ) ) {
$url = admin_url();
} else {
@jimboobrien
jimboobrien / force-ssl.php
Created September 20, 2017 23:30 — forked from wpscholar/force-ssl.php
Force SSL on pages in WordPress
<?php
/**
* Force SSL on pages in WordPress
*/
function force_ssl(){
if( !is_ssl() ){
$url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
wp_redirect( $url, 301);
exit();
@jimboobrien
jimboobrien / format-address.php
Created September 20, 2017 23:30 — forked from wpscholar/format-address.php
Format an address
<?php
/**
* Takes an array containing address elements and outputs a formatted address.
*/
function get_formatted_address( $address, $args = array() ) {
$before = isset( $args['before'] ) ? $args['before']: '';
$after = isset( $args['after'] ) ? $args['after']: '';
$format = ( isset( $args['format'] ) && 'block' == $args['format'] ) ? 'block': 'inline';
$formatted_address = '';
@jimboobrien
jimboobrien / downloadable-csv.php
Created September 20, 2017 23:29 — forked from wpscholar/downloadable-csv.php
Takes an array of data and create a csv file that will automatically download
<?php
/**
* Takes an array of data and creates a csv file that will automatically download
*/
function downloadable_csv( $data, $filename = 'data_csv' ){
/*
Sample Data Format:
array(
'headings' => array(),
@jimboobrien
jimboobrien / show-custom-post-types.php
Created September 20, 2017 23:29 — forked from wpscholar/show-custom-post-types.php
Show WordPress custom post types on the main blog and archive pages
<?php
/**
* Show WordPress custom post types on the main blog and archive pages
*
* @param WP_Query $query
**/
function show_custom_post_types( $query ) {
// Show all custom post types on main blog and archive pages
@jimboobrien
jimboobrien / is_plugin_active.php
Created September 20, 2017 23:29 — forked from wpscholar/is_plugin_active.php
Test if a WordPress plugin is active
<?php
/**
* Test if a WordPress plugin is active
*/
if ( is_plugin_active('plugin-directory/plugin-file.php') ) {
// the plugin is active
}
@jimboobrien
jimboobrien / customize-wp-login.php
Created September 20, 2017 23:29 — forked from wpscholar/customize-wp-login.php
Customize the login form in WordPress
<?php
/**
* Customize the login form in WordPress
* @author Micah Wood <micah@wpscholar.com>
*/
/**
* Change the href for the logo link on login page to point to the main site
*/
add_filter( 'login_headerurl', 'change_login_headerurl' );