Site Name, Tagline and URL Shortcodes
Adds [site_name], [site_tagline] and [site_url] shortcodes so text that mentions your site stays correct if you rename or move it.
Opens WPIDE on
Code
add_shortcode( 'site_name', function () {
return esc_html( get_bloginfo( 'name' ) );
} );
add_shortcode( 'site_tagline', function () {
return esc_html( get_bloginfo( 'description' ) );
} );
add_shortcode( 'site_url', function ( $atts ) {
$atts = shortcode_atts( array( 'link' => 'no' ), $atts, 'site_url' );
$url = home_url( '/' );
return 'yes' === $atts['link'] ? '<a href="' . esc_url( $url ) . '">' . esc_html( untrailingslashit( preg_replace( '#^https?://#', '', $url ) ) ) . '</a>' : esc_html( $url );
} );
Notes
[site_url link="yes"] prints a clickable link instead of plain text.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.