Skip to content

Instantly share code, notes, and snippets.

View dartiss's full-sized avatar
🏠
Always working from home

David Artiss dartiss

🏠
Always working from home
View GitHub Profile
@dartiss
dartiss / plugin-status.php
Last active February 14, 2018 14:15
Check the current state of a WordPress Plugin
<?php
function check_plugin_status( $plugin_dir, $plugin_name = '' ) {
if ( '' == $plugin_name ) { $plugin_name = $plugin_dir . '.php'; }
if ( is_plugin_active( $plugin_dir . '/' . $plugin_name ) ) {
$status = 2;
} else {
@dartiss
dartiss / functions.php
Created November 15, 2017 18:15
WordPress Plugin to List all Site Cookies
<?php
function get_cookies( $paras = '', $content = '' ) {
if ( strtolower( $paras[ 0 ] ) == 'novalue' ) { $novalue = true; } else { $novalue = false; }
if ( $content == '' ) { $seperator = ' : '; } else { $seperator = $content; }
$cookie = $_COOKIE;
ksort( $cookie );
@dartiss
dartiss / functions.php
Created November 15, 2017 18:19
Displays Number of Published WordPress Posts
<?php
function post_count_sc( $paras = '', $content = '' ) {
return wp_count_posts() -&gt; publish;
}
add_shortcode( 'post_count', 'post_count_sc' );
?>
@dartiss
dartiss / functions.php
Created November 15, 2017 18:23
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' );
@dartiss
dartiss / functions.php
Created November 15, 2017 18:27
WordPress Plugin to Suppress Skimlinks Output
<?php
function skim_suppress( $paras = '', $content = '' ) {
return '<div class="noskim">'. do_shortcode( $content ) . '</div>';
}
add_shortcode( 'noskim', 'skim_suppress' );
?>
@dartiss
dartiss / functions.php
Created November 15, 2017 18:32
WordPress function get_the_shortlink
<?php
function get_the_shortlink() {
$post_id = get_the_ID();
if ($post_id!="") {$shortlink=home_url()."/?p=".$post_id;} else {$shortlink="";}
return $shortlink;
}
?>
@dartiss
dartiss / functions.php
Last active January 23, 2018 15:29
WordPress shortcode to add a Wikipedia link to post text
function wikilinker_shortcode( $paras = '', $content = '' ) {
// Extract the shortcode parameters
extract( shortcode_atts( array( 'alt' => '', 'rel' => '', 'lang' => 'en', 'target' => '' ), $paras ) );
// If an alternative link is specified use that rather than the linked text
if ( '' != $alt ) { $lookup = $alt; } else { $lookup = $content; }
@dartiss
dartiss / function.php
Last active March 8, 2018 09:22
Adding AdSense Auto ads to your WordPress site
function google_autoads() {
?>
[[insert your AdSense script here]]
<?php
}
add_action( 'wp_head', 'google_autoads' );
@dartiss
dartiss / functions.php
Last active March 25, 2018 15:43
Add Gutenberg promo to the site of WordPress posts
<?php
function add_gutenberg_promo( $content ) {
global $post;
if ( function_exists( 'gutenberg_post_has_blocks' ) && gutenberg_post_has_blocks( $post->ID ) && is_single() ) {
$content = '<div style="background:#fff8c4; border:1px solid #f2c779; border-radius:10px; padding:10px; margin-bottom:10px;">This post was created using Gutenberg, the new editor, coming soon, for WordPress. You can <a href="https://wordpress.org/gutenberg/">learn more about it here</a>, <a href="https://wordpress.org/plugins/gutenberg/">try the Beta plugin</a> or simply <a href="https://testgutenberg.com">try it out for yourself</a>, no site required.</div>' . $content;
}
<?php
function embed_code( $content ) {
global $post;
$i = 1;
while ( $i < 6 ) {
$code = 'CODE' . $i;