Shortcode - WpScriptly

Displaying website title with a short code

This guide provides a detailed explanation on how to use a short code to dynamically display the title of a website. It covers the steps required to create and implement a short code that retrieves and displays the site’s title. This functionality can be particularly useful for web developers and content managers who want to ensure consistent and automatic display of the website’s title across different sections of their site. The guide includes practical examples and best practices to help users seamlessly integrate this feature into their web pages, enhancing both the efficiency of content management and the user experience.

I use fluent snippet plugin for all my functions, JS and CSS needs

PHP Script

function website_name_shortcode($atts, $content = null) {
// Get the website name
$website_name = get_bloginfo('name');
// Return the website name within a CSS class
return '<span class="website-name">' . esc_html($website_name) . '</span>';
}
add_shortcode('website_name', 'website_name_shortcode');

CSS

.website-name  { 
 color: #000;
 font-weight: 600;
}

Shortcode to be used on the website

Wp Scriptly

Example image:

Displaying website title with a short code
Displaying website title with a short code

Please customize the css any way that will match your website.

Notes:

Wp Scriptly

These scripts, CSS styles, and plugins are designed to work best with minimal interference from themes or other plugins. If conflicts arise, adjustments may be needed.
Please note that they must be used as is.”

Let me know if you’d like any further refinements!

Wp Scriptly

Was this information helpful?

Comments: