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:
Please customize the css any way that will match your website.
Notes:
This basic script, CSS style, and plugin are designed to function optimally assuming minimal interference from your theme or other plugins. If conflicts occur or further customization is needed, additional adjustments may be necessary. Please note that this script, CSS style, or plugin must be used AS IS.
Wp Scriptly
Comments: