Skip to content

Instantly share code, notes, and snippets.

@dartiss
Created November 15, 2017 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dartiss/6a4186539f2e5acbd594a81179f5f8eb to your computer and use it in GitHub Desktop.
Save dartiss/6a4186539f2e5acbd594a81179f5f8eb to your computer and use it in GitHub Desktop.
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