Created
November 15, 2017 18:23
-
-
Save dartiss/6a4186539f2e5acbd594a81179f5f8eb to your computer and use it in GitHub Desktop.
WordPress Plugin to Display Your Site's Current PageRank
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 | |
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>. '&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' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.