This file contains 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 | |
/** | |
* Add additional contact methods to a WordPress user profile | |
*/ | |
function more_contactmethods( $contactmethods ) { | |
$contactmethods['twitter'] = 'Twitter username'; | |
$contactmethods['facebook'] = 'Facebook URL'; | |
return $contactmethods; | |
} |
This file contains 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 | |
/** | |
* Add a settings link to your WordPress plugin on the plugin listing page. | |
*/ | |
function add_settings_link( $links, $file ){ | |
if( $file == plugin_basename(__FILE__) ){ | |
$settings_link = '<a href="'.admin_url('admin.php?page=my-page').'">'.__('Settings', $this->textdomain).'</a>'; | |
array_unshift( $links, $settings_link ); | |
} |
This file contains 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 | |
/** | |
* 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( |
This file contains 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 | |
/** | |
* 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() ) |
This file contains 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 | |
/** | |
* 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>'; | |
} |
This file contains 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 | |
/** | |
* 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; |
This file contains 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 | |
/** | |
* 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 |
This file contains 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 | |
/** | |
* WordPress contextual template loading | |
*/ | |
function mpress_load_template( $name ){ | |
if( is_front_page() ){ | |
if( is_home() ){ | |
return locate_template( array( | |
$name.'-home.php', |
OlderNewer