Hot answers tagged bloginfo
9
We have to look a bit deeper here to get an answer to your question.
So, bloginfo is a simple wrapper around get_bloginfo.
<?php
function bloginfo( $show='' ) {
echo get_bloginfo( $show, 'display' );
}
Notice the second argument display. Let's see what that does.
<?php
function get_bloginfo( $show = '', $filter = 'raw' ) {
// snip snip, ...
5
To make a long story short: get_bloginfo( 'template_directory' ) and get_bloginfo( 'template_url' ) simply return get_template_directory_uri().
So, you can shortcut that second call simply by referring directly to the latter template tag.
Refer to source for get_bloginfo().
A few others:
'url' => home_url()
'wpurl' => site_url()
'stylesheet_url' => ...
3
get_stylesheet_directory_uri() returns a value, it doesn’t print anything. So you have to use:
echo get_stylesheet_directory_uri();
get_template_part() is just a wrapper for locate_template(). But the latter has one advantage: It returns the path of the file it has found. Try the following:
$path = locate_template( 'sidebar-front.php', TRUE );
echo ...
3
You cannot use bloginfo() while your are outputting using echo because bloginfo it self also out puts string using echo. Below will work for you, you also have extra double quote which i have removed....
<?php
$attch_id_1 = pn_get_attachment_id_from_url(get_post_meta($post->ID, 'img1', true));
$image_attributes_1 = ...
3
The difference in your case is in filters being applied to output of these functions.
While bloginfo applies one of these filters:
if ( 'display' == $filter ) {
if ( $url )
$output = apply_filters('bloginfo_url', $output, $show);
else
$output = apply_filters('bloginfo', $output, $show);
}
Function home_url ...
2
Open your backend and go to Settings/General. You will see to input fields:
WordPress Address (URL)
Site Address (URL)
The first one correspond to site_url() and the second one to home_url()
So why is there a difference? Because WordPress is able to start from a different site then your blog posts. For example, create a page called 'homepage' and enter ...
1
How to make title for home to be News, but if page has parent then its name else just post/page name
Put this in your functions.php:
function my_title() {
if (is_home())
echo 'News';
else {
global $post;
if ($post->post_parent)
echo get_post($post->post_parent)->post_title;
else echo $post->post_title;
}
} // function my_title
and then use <?php my_title(); ?> anywhere you want.
...
1
You can access that, using the additional variable in the Filter Functions.
The Filter bloginfo_url uses the $show parameter (the parameter you use when calling bloginfo) and passes it to apply_filters.
So hooking into bloginfo_url should be no problem, you just have to make a switch inside the function, and it only applies to e.g. url .
This would be the ...
1
Use get_stylesheet_directory_uri() and get_template_directory_uri() instead. Note that these functions return rather than echo their result. So, for example:
<img src="<?php echo get_template_directory_uri();?>/images/Lynx.gif" alt="castandtubular"/>
1
You can't check the context while the filter callback is called, because the element is already in the frontend. There are 3 solutions though:
1. jQuery
Search for the element and add html to the places in the name.
2. PHP in element
Get the bloginfo('name'); in the element and change it on that place using PHP.
3. PHP in header
Add HTML to your ...
Only top voted, non community-wiki answers of a minimum length are eligible
