Hot answers tagged

15

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' => ...


13

get_bloginfo('url') calls home_url() calls get_home_url() reads option home get_bloginfo('wpurl') calls site_url() calls get_site_url() reads option siteurl get_bloginfo('siteurl') and get_bloginfo('home') are deprecated arguments and return get_bloginfo('url') (siteurl argument is documented wrong in Codex as equal to wpurl, it's not in current code) The ...


11

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, ...


6

The two functions output exactly the same thing. From the Codex entry for get_bloginfo(): 'name' - Returns the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table. From source: case 'name': default: $output = get_option('blogname'); Neither get_bloginfo() nor bloginfo() do any sort ...


4

While there is no inherent caching in get_bloginfo(), most of information it retrieves is from options and get_option() is cached. Holding value you need in a variable for using several time is still (marginally in most cases) faster than function call, but I wouldn't bother with explicit dedicated caching.


4

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 ...


4

bloginfo() is using echo, you need a function that returns its value: get_bloginfo(). In this case you could also use just the function get_bloginfo() is using: get_template_directory_uri().


4

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 ...


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

From 'wp-includes/general-template.php' function get_bloginfo( $show = '', $filter = 'raw' ) { switch( $show ) { case 'home' : // DEPRECATED case 'siteurl' : // DEPRECATED _deprecated_argument([snipped]); case 'url' : $output = home_url(); break; case 'wpurl' : $output = site_url(); break; ...


3

Taken from the source code of get_bloginfo(), Here is a very very simple class you can utelize and extent at your will. I have decided to make use of methods, making properties public from a class is really not great coding and not recommended. I know Wordpress thrive on public properties, but that is Wordpress. Here is the class (which you should convert ...


2

Ptriek's example checks if the value is true and unfortunately an empty value still evaluates to true, hence why it doesn't work as expected. Try the following instead.. <?php if( !empty( get_bloginfo('description') ) : ?> <!-- your html --> <?php endif; ?> NOTE: An empty check will also ring true for empty strings, so covers exactly ...


2

if ( get_bloginfo( 'description' ) ) { //do something } bloginfo echoes the description, get_bloginfo returns php variable


2

What you have: <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/style.css"> should work fine. I've copied and pasted into my header.php and it worked. But this is not how you should be including css or javascript files. The proper way is to use the wp_enqueue_scripts hook. For instance, say you have javascript ...


2

Here's what I use: function oenology_copyright() { global $wpdb; $copyright_dates = $wpdb->get_results(" SELECT YEAR(min(post_date_gmt)) AS firstdate, YEAR(max(post_date_gmt)) AS lastdate FROM $wpdb->posts WHERE post_status = 'publish' "); $output = ''; ...


2

get_bloginfo returns strings so this works fine: <?php $language = get_bloginfo( 'language' ); if(language == 'en-US') the_time('jS F Y'); else the_time('d/m/Y'); ?>


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 ...


2

try this 'href'=> admin_url("post-new.php?post_type=albertis-kunstwerke")


2

Try these filters instead // changing the logo link from wordpress.org to your site function mb_login_url() { return home_url(); } add_filter( 'login_headerurl', 'mb_login_url' ); // changing the alt text on the logo to show your site name function mb_login_title() { return get_option( 'blogname' ); } add_filter( 'login_headertitle', 'mb_login_title' ); ...


2

You will need to use site_url($path_to_style_sheet, 'https') instead of bloginfo(). The home_url() method also supports https.


2

The meta description isn't part of the Twenty Fifteen theme. You mentioned the Yoast plugin in a previous question yesterday, so I guess the meta description comes from there. According to their API page, there's a filter called wpseo_metadesc that might be what you're looking for. Here's an untested example: /** * Change the Yoast meta description for ...


1

You are using paths relative to the current directory. Try this (untested) echo "$i. <option value='" . home_url('/groundfish-meetings/' . $file) . "'>$file</option>";


1

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

To avoid using deprecated call bloginfo('home') added new function to qtranslate_core.php: function qtrans_convertHomeURL($url, $what) { if($what=='/') return qtrans_convertURL($url); return $url; } and new filter to qtranslate_hooks.php: add_filter('home_url', 'qtrans_convertHomeURL', 10, 2); This way no other changes were needed. Not the best ...


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

If your style.css is in /wp-content/themes/themedirectory, and your image is at /wp-content/themes/themedirectory/images/image.jpg, then your css will be this: background-image: url("images/image.jpg"); You can't use php in a css file, it will not parse unless included via php (instead of with <link>).


1

A bit late on this but I just ran into the same issue. My problem was I had changed out all my theme files with an empty starter template theme and did not go through the theme's install steps so it was not getting the correct directory. Re-activating the theme might be an appropriate first step in finding a solution to this problem.


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 ...


1

You should include using the server path rather than the URL. This will give you access to WordPress functionality. include('extras/floater.php'); Update: The following is to further explain why it's a bad practice to include the file via URL. Here's what's happening: There is an innate inheritance when you include a file via server path. It has access ...



Only top voted, non community-wiki answers of a minimum length are eligible