Skip to content

Instantly share code, notes, and snippets.

😀
Happy

Micah Wood wpscholar

😀
Happy
Block or report user

Report or block wpscholar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wpscholar
wpscholar / wp-add-contact-method.php
Last active Apr 8, 2018
Add additional contact methods to a WordPress user profile
View wp-add-contact-method.php
<?php
/**
* Add additional contact methods to a WordPress user profile
*/
function more_contactmethods( $contactmethods ) {
$contactmethods['twitter'] = 'Twitter username';
$contactmethods['facebook'] = 'Facebook URL';
return $contactmethods;
}
@wpscholar
wpscholar / wp-plugin-settings-link.php
Last active Oct 7, 2018
Add a settings link to your WordPress plugin
View wp-plugin-settings-link.php
@wpscholar
wpscholar / wp-snapshot-shortcode.php
Last active Mar 21, 2019
Shortcode displays snapshots of remote sites on your WordPress site.
View wp-snapshot-shortcode.php
<?php
/**
* This shortcode will allow you to create a snapshot of a remote website and post it
* on your WordPress site.
*
* [snapshot url="http://www.wordpress.org" alt="WordPress.org" width="400" height="300"]
*/
add_shortcode( 'snapshot', function ( $atts ) {
$atts = shortcode_atts( array(
@wpscholar
wpscholar / members-only-shortcode.php
Last active Sep 20, 2017
WordPress shortcode will only display content to registered users.
View members-only-shortcode.php
<?php
/**
* WordPress shortcode only displays content to registered users. Could be improved by
* passing role as an attribute to only allow certain types of users.
*
* Example: [member]This text will be only displayed to registered users.[/member]
*/
function members_only_shortcode( $atts, $content = null ) {
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
@wpscholar
wpscholar / load-pdf.php
Last active Sep 20, 2017
WordPress shortcode loads a PDF file on your site in an iframe using Google Docs
View load-pdf.php
<?php
/**
* WordPress shortcode loads a PDF file on your site in an iframe using Google Docs.
*
* Example: [embed_pdf width="600px" height="500px"]http://infolab.stanford.edu/pub/papers/google.pdf[/embedpdf]
*/
function embed_pdf($attr, $url) {
return '<iframe src="http://docs.google.com/viewer?url=' . $url . '&embedded=true" style="width:' .$attr['width']. '; height:' .$attr['height']. ';" frameborder="0">Your browser should support iFrame to view this PDF document</iframe>';
}
@wpscholar
wpscholar / rss-shortcode.php
Last active Sep 20, 2017
WordPress shortcode allows you to create content that is visible only in your RSS feeds.
View rss-shortcode.php
<?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;
@wpscholar
wpscholar / remove-admin-menu-items.php
Last active Sep 20, 2017
Remove unwanted pages from the WordPress admin menu
View remove-admin-menu-items.php
<?php
/**
* Remove unwanted pages from the WordPress admin menu
*/
function my_admin_menu() {
remove_menu_page('link-manager.php');
}
add_action( 'admin_menu', 'my_admin_menu' );
@wpscholar
wpscholar / pagination.php
Last active Jan 9, 2019
Create numeric pagination in WordPress
View pagination.php
<?php
/**
* Create numeric pagination in WordPress
*/
// Get total number of pages
global $wp_query;
$total = $wp_query->max_num_pages;
// Only paginate if we have more than one page
@wpscholar
wpscholar / append-nav-items.php
Last active May 27, 2018
Add a custom link to the end of a menu that uses the wp_nav_menu() function
View append-nav-items.php
<?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>';
}
@wpscholar
wpscholar / contextual-template-loading.php
Last active Sep 27, 2015
WordPress Contextual Template Loading
View contextual-template-loading.php
<?php
/**
* WordPress contextual template loading
*/
function mpress_load_template( $name ){
if( is_front_page() ){
if( is_home() ){
return locate_template( array(
$name.'-home.php',
You can’t perform that action at this time.