Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress Plugin to Display Your Site's Current PageRank
<?php
function pagerank_sc( $paras = '', $content = '' ) {
$cache_key = 'functions_pagerank';
$cache = get_transient( $cache_key );
if ( !$cache ) {
$fileout = wp_remote_get( 'http://prapi.net/pr.php?url=' . <code>get_site_url() </code>. '&amp;f=text' );
if ( isset( $fileout[ 'body' ] ) ) {
$content = $fileout[ 'body' ];
set_transient( $cache_key, $content, 86400 );
}
} else {
$content = $cache;
}
return $content;
}
add_shortcode( 'pagerank', 'pagerank_sc' );
?>
@dartiss
Copy link
Author

dartiss commented Nov 15, 2017

If you have a need to add your site's current PageRank to a page or post, the following piece of code, added to your theme's functions.php file, will achieve just that.

All you have to add in a post or page is add [pagerank] wherever you wish the PageRank to appear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment