Skip to content

Instantly share code, notes, and snippets.

@oneblackcrayon
Created August 18, 2016 02:07
Show Gist options
  • Save oneblackcrayon/39cca72566f2e635d17aa7f8711e18a4 to your computer and use it in GitHub Desktop.
Save oneblackcrayon/39cca72566f2e635d17aa7f8711e18a4 to your computer and use it in GitHub Desktop.
Display the site name and other bloginfo callable info as shortcode
<?php
/**
* Plugin Name: Bloginfo Shortcode
* Description: Allows bloginfo() as a shortcode.
* Author: Giuseppe Mazzapica
* Author URI: http://gm.zoomlab.it
* License: MIT
* @link: http://wordpress.stackexchange.com/questions/173871/how-to-display-the-site-name-in-a-wordpress-page-or-post
*/
add_shortcode('bloginfo', function($atts) {
$atts = shortcode_atts(array('filter'=>'', 'info'=>''), $atts, 'bloginfo');
$infos = array(
'name', 'description',
'wpurl', 'url', 'pingback_url',
'admin_email', 'charset', 'version', 'html_type', 'language',
'atom_url', 'rdf_url','rss_url', 'rss2_url',
'comments_atom_url', 'comments_rss2_url',
);
$filter = in_array(strtolower($atts['filter']), array('raw', 'display'), true)
? strtolower($atts['filter'])
: 'display';
return in_array($atts['info'], $infos, true) ? get_bloginfo($atts['info'], $filter) : '';
});
// The plugin above can be used to output (almost) all the informations that get_bloginfo() is capable to return, I just removed the deprecaded and discouraged informations.
// Usage
// If you have the code above in a MU plugin, or in an active plugin you can output site name in this way:
// [bloginfo info='name']
// All the informations you can get are listed in the $infos array.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment