Register in the functions.php to add a new autogenerated image size for you posts and pages. Use name, width and height attributes to define the new size. By passing 9999 as a value of width or height the image will retain its original size for that dimension.
Use this filter to add a slug-based css class to each menu item.
functionadd_menu_item_slug_class($classes,$item,$args){$item_class=sanitize_title($item->title);// Convert title to a slug$classes[]="menu-item-".$item_class;return$classes;}add_filter('nav_menu_css_class','add_menu_item_slug_class',1,3);
bloginfo function prints information about your site. Pass an argument to return name, description, wpurl, url, admin_email, charset, version, html_type, text_direction, language, stylesheet_url, stylesheet_directory, template_url, pingback_url and more.
When registering a new custom post type you can encounter a bug where a single custom post returns a 404 page even when a valid page template exists. To fix it add the following snippet to the functions.php file. Make sure to remove it once the bug is fixed as you do not want it to run with each page load.
Pass arguments to WP_Query with a tag of a custom post.
<?php// args$args=array('post_type'=>'custom-post','order'=>'ASC','posts_per_page'=>-1// Get all posts);$the_query=newWP_Query($args);?><?phpif($the_query->have_posts()):?><?phpwhile($the_query->have_posts()):$the_query->the_post();?><ahref="<?phpthe_permalink();?>"><?phpthe_title();?></a><?phpendwhile;?><?phpendif;?><?phpwp_reset_query();// Reset loop ?>
In the root directory open the wp-config.php file and add following code after the "That's all, stop editing! Happy publishing" message. Next, login to your WordPress admin panel and go to Tools > Network Setup to configure it.
Enqueue WordPress dashicons to frontend. By default dashicons are only available in the admin area. Add the following code to the functions.php file to use WordPress icons anywhere in your website.
Using get_bloginfo lets you access information about your site. Pass an argument to return name, description, wpurl, url, admin_email, charset, version, html_type, text_direction, language, stylesheet_url, stylesheet_directory, template_url, pingback_url and more.
get_post returns an object holding information about the post. By passing an argument you can access object arguments and return the data. Available data - ID, post_author, post_date,post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type and comment_count.
The following methods allow for getting and displaying translated text in your theme.
// Get text__('Your text','text_domain');// Get text with a specified context_x('Your text','Form label','text_domain');// Echo out text_e('Your text','text_domain');// Use translated text inside of sprintf methodechosprintf('This is %s in a paragraph',__('your text','text_domain'));
Helper function for displaying the post thumbnail. Default Wordpress image sizes - thumbnail|medium|medium_large|large|full. Default WooCommerce image types - shop_thumbnail|shop_catalog|shop_single.
Set a global variable as part of the functions.php file.
// Add this function in function.php filefunctionset_some_global_variable(){global$some_variable;$some_variable=1;}add_action('after_setup_theme','set_some_global_variable');// Than, it can be used in other parts of the themeglobal$some_variable;echo$some_variable;