Whati is the diffrence between bloginfo and template_directory_uri? - wordpress

I want to clear my concept that what is the difference between blog_info() and template_directory_uri() function? Please in details would be helpful!
Thanks

As you can see in the source, get_bloginfo( 'template_directory' ) and get_bloginfo( 'template_url' ) are simply wrappers for get_template_directory_uri():
case 'template_directory':
case 'template_url':
$output = get_template_directory_uri();
break;

IF you check with these links blog_info and template_directory_uri links you can clearly understand what is the difference between these two functions.
Anyway let me explain this for you
template_directory_uri
This function provides you the complete url to the theme directory you are currently using. Suppose if you are using theme x in your wordpress front-end, then when you call template_directory_uri() function it will return http://yourdomainname.com/wp-content/themes/x. This essentialy means that this function returns template directory URI for the current theme being used.
bloginfo
What this function does is that it will return all the information associated with your site which are set in the admin general settings and admin user profile. This function gives you information about the site url, admin email , site name, site description and lot of things. Most of these are available in the General Settings menu in the admin back-end. The bloginfo function accepts an input parameter. If you do not pass any input parameter by default it will show the Site title which is set in the admin back end. You can pass various other inputs like description, url, charset, version etc. These will give the info associated with them. So what bloginfo gives us is, it will provide the information regarding the site.
From bloginfo function we can get template_uri too, just do bloginfo('template_url');
If you prints out both these functions in your php page in wordpress theme, you can clearly found out what is the difference between these two functions. May be go to your index.php and just print out these two:
echo get_template_directory_uri();
bloginfo('name');
Hope this helps you

Related

Where is Wordpress search parameter checked?

This is going to sound stupid but I am stymied. As I've learned a search form is recognised by Wordpress when the name of the input is gives as 's'. The action is always the home url. But nowhere in index.php or page.php(depending on your homepage setting) does it check for the parameter 's'. Where exactly does Wordpress check for this parameter?
I am trying to output the search result on a particular page but it does not work when I set the 'action' value to anything but the Home URL. I am hoping I can gain further understanding on how search works and maybe implement the same parameter checking in my desired page
Howdy_McGee check this out
WordPress doesn't require that search goes back to the homepage. The s query var is a reserved keyword for WordPress search. What you can do is modify your search form to include the current url:
global $wp;
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( $wp->request ) ); ?>">
By doing so on a term page ( taxonomy archive ) it will also restrict the search to that specific term without any additional work. You can modify this in your searchform.php template. If you don't have one you can grab it from the 2017 theme files.
WordPress parse most requests through the class-wp-query.php file handed by the WP_Query Class/Object. Search is handled by WP_Query::parse_search()
If you're looking to modify the search or really any queries you can always use pre_get_posts to change the query object before it's requested from the database. If you want to modify the SQL before it's requested you can use the posts_clauses hook, usually this is used for incorporating custom tables.

Wordpress/ACF Image Field HTTPS/SSL

When using the “image” type custom field, and also having a Return Value of “Image URL”, and then in my template using <img src="<?php the_field('mycustomimage'); ?>">, it’s returning an http URL instead of an https URL, causing mixed content on my site. Other areas of the site are returning an https URL, like when I use wp_get_attachment_image_src(); for example.
How do I get it to return an https URL?
There's a variety of Insecure Content Fixing plugins out there, as well as Simple SSL Setup plugins that work well. There's also some documentation in the Codex that may help.
If neither of those fix your issue, you can simply do a string replace on the returned values. Note you may want to instead use the returning get_ functions instead of the echoing the_ functions for ease of use:
<img src="<?= str_replace( 'http://', 'https://', get_field( 'mycustomimage' ) ); ?>">
Also make sure your site is set to https:// in your General Settings if its not already
Edit:
In regards to your comment: Was the admin secured with https:// when the images were uploaded? Also the insecure content fixer and simple ssl setup plugins should effectively just require activation (or network activate) and basically be good to go.
If those don't work, you've modified all DB records, and everything should be working, you could always do a runtime find and replace, while it's a bit hacky, I have actually used code similar to this for a similar purpose before when some things just "stuck" to an old protocol despite everything saying they should be updated to a new one.
add_action( 'template_redirect', function() use($startTime){
ob_start( function( $buffer ){
if( is_ssl() ) $buffer = str_ireplace( 'src="http://', 'src="https://', $buffer );
return $buffer;
});
});
Note that this will require anything with a src attribute to have an appropriately SSL'd resource, including external resources (iframes, scripts, etc.) - otherwise you'll need to complicate it a bit with preg_replace_callback() and some regular expressions to only grab img tags.

WordPress functions.php - Admin html injection and submitting forms

I created a new navigation item on the left for my WP Admin:
add_action( 'admin_menu', 'addManagementMenuItem' );
function addManagementMenuItem(){
add_menu_page('Issue Management', 'Issue Management', 'manage_options', 'issue_management_slug', 'issue_management_building_function','',3);
}
function issue_management_building_function(){
if(!current_user_can('manage_options')){
}
else {
?>
...
...
So where I have the ellipsis ... is where my HTML begins and I write out some information to the page with various php echo statements to print some data out.
What I would like to do is now give the user the ability to enter in a filter and press submit. This would issue a POST to another page which would receive the post data, run some stuff, and spit out something else to the screen. I was just thinking this would take the user away from the WP-ADMIN area entirely (what I want to do is keep the user all within the right pane so it looks like it's natively happening on WordPress under my new admin area)
Something feels wrong about this approach above where I'm putting tons of html into functions.php - what is the way to create pages for a custom admin section where I can do things like post forms and go to multiple pages?
I was thinking the best solution would be to put an iframe in my injected HTML in functions.php, and then the pages can talk to themselves just like normal behind the scenes in WP-admin.
Could anyone point me in the right direction?
thanks!
Considering the user input/_POST features you'd like to add to this, you may want to consider building this functionality out as your own plugin. I've always kept custom functionality limited to non-user interaction in the functions.php file, but anything further would probably be better fit as it's own plugin.
For example, what if you created a plugin directory named nullhypothesis:
add_action( 'admin_menu', 'addManagementMenuItem' );
function addManagementMenuItem(){
add_menu_page('Issue Management', 'Issue Management', 'manage_options', 'nullhypothesis/file_to_do_your_bidding.php', 'issue_management_building_function','',3);
}
It's that fourth parameter that in the documentation mentions that you should include the menu_slug, but it doesn't necessarily need to only be a function - it can also be a file you define.
Then, in your file_to_do_your_bidding.php file (within your plugin), you can add whatever _POST functionality you'd need it to. It could also exist as the 'admin' page that the administrator/whoever interacts with.
Was that what you were looking for?

How to create a profile page in Wordpress Multisite

I can't find a way to create a front-end profile page for all users under Wordpress Multisite Network. I also wanted the profile page to be on the main site and not on sub-sites if possible. I don't want to use any social network plugins like buddypress.. I just want to create a page like http://mainsite.com/profile/username
Is there a way to accomplish this?
Maybe you might check out Buddypress which is a social layer on top of Wordpress and is able to do what you need (i.e. something like http://mainsite.com/profile/username).
Link: http://buddypress.org/
More specifically, in Buddypress the default behaviour is http://mainsite.com/members/username
I have noticed that you have edited the question and that you are looking for a way to accomplish this without any plugin. There are a series of tags in Wordpress to show the author's data. So basically you could create a page and then use the_author_meta tags. For example the following code echoes the first and last name of a user whose name is stored in $userID:
<?php
$pagename = $userID;
echo the_author_meta(user_firstname, $userID );
echo the_author_meta(user_lastname, $userID );
?>
Please note that the variable $pagename is empty in case you use a static page as home page, but it is not your case.
Source: https://codex.wordpress.org/Template_Tags/the_author_meta

Wordpress theme name inside theme php files, what is the purpose of this?

I've been building basic themes now for nearly a year, and I'm trying to clean up my style as much as possible. But I don't know where to look to find out what this does...
In the kubrick theme php files, for example you get a php tag like this...
<?php the_content('<p class="serif">' . __('Read the rest of this entry »', 'kubrick') . '</p>'); ?>
You see the theme name 'kubrick' weaved in. What is the purpose of this?
You see it in all themes, twentyten, twentyeleven, etc.. but I never notice a difference if I leave it the same. What benefits does this have if I change it to my current theme name?
Can anyone enlighten me? or point me in the right direction?
Thanks
Josh
This is the 'theme text domain' and is typically used for localization. You can find out more by reading the gettext filter reference. One note is that the text domain is not required to be the same as your theme name. You can make it whatever you want as long as you are consistent with what you load using load_theme_textdomain. It's just convention to make it the same as your theme name. Finally, as to why you should bother including a domain here is a quote from an article called How to localize WordPress themes and plugins with GetText:
Have you noticed the 2nd argument in the GetText calls? It’s an
optional argument that tells GetText what the scope (domain) of the
texts is. If supplied, this GetText will return the translations only
from the dictionary that you supply with that domain name. Although
optional, specifying the translation domain is highly recommended.
Without it, GetText might return a different translation, if the same
string also appears in a different plugin, or in WordPress.

Resources