Function bloginfo output via shortcodes
WordPress has a great feature bloginfo() with which you can display basic user information on your site. This function can be used anywhere in your blog template, but what if you need to use the data, which are returned by the function in the article itself. Correct answer is one, need to use shortcodes.
To use shortcodes, which will output the same information, which the function outputs bloginfo() required in file functions.php your theme insert a special hook.
1 2 3 4 5 |
function bloginfoSC( $atts ) { extract(shortcode_atts(array( 'value' => '', ), $atts)); return get_bloginfo($value); } add_shortcode('bloginfo', 'bloginfoSC'); |
After adding the hook, the data will be displayed using the shortcode [bloginfo value=’name’]. Let me give you a few more examples for clarity.:
1 2 3 4 |
[bloginfo value='name'] [bloginfo value='url'] [bloginfo value='description'] [bloginfo value='charset'] |
And now let's consider what the value attribute can be and what it can display if it is entered into the shortcode.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
name = Blog name description = Blog description admin_email = admin@email.com url = https://example/home wpurl = https://example/home/wp stylesheet_directory = https://example/home/wp/wp-content/themes/child-theme stylesheet_url = https://example/home/wp/wp-content/themes/child-theme/style.css template_directory = https://example/home/wp/wp-content/themes/parent-theme template_url = https://example/home/wp/wp-content/themes/parent-theme atom_url = https://example/home/feed/atom rss2_url = https://example/home/feed rss_url = https://example/home/feed/rss pingback_url = https://example/home/wp/xmlrpc.php rdf_url = https://example/home/feed/rdf comments_atom_url = https://example/home/comments/feed/atom comments_rss2_url = https://example/home/comments/feed charset = UTF-8 html_type = text/html language = en-US text_direction = ltr version = 3.1 |
Here is such a small, but I think a useful post for today, follow us and good luck in website development.
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.