Wordpress Tutorials
- Wordpress
- Directory and file structure.
- Wordpress configuration
- Htaccess Configuration
- WP-CONTENT user playground
- Increase file size loading in phpmyadmin on localhost.
- Fatal error: Allowed memory size of x bytes
- wordpress Dashboard
- How to set local host domain or Virtual host
- Header, index and footer page.
- How to create wordpress Themes
- Html to wordpress themes
- Child Themes
- Increase Upload Max Filesize
- wp_enqueue_style & script
- How to make plugin
- Create Plugin
- Insert data into table using plugin.
- Show data from database
- Hook & Filter
- Template Or Custom page template
- Custom Login template
- How to show post on diffrent page.
- Custom widgit
- How to use contact form 7 plugin.
- Wordpress Database
- How to use Duplicator plugin
- How to fix Fatal Error: Maximum Execution Time Exceeded in WordPress
- How to debuggin mode on in wordpress
- Auto update plugin and themes
- How to Transfer WordPress
- How to change a WordPress site URL
- Top 10 issues in wordpress
- wordpress website link
Wordpress setting
Wordpress Function
wordpress top 10 problems
Important Links
Header Page in wordpress.
language_attributes ( string $doctype = 'html' )
Displays the language attributes for the html tag.
<!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js">
Displays the language attributes for the <html> tag.
<?php language_attributes( $doctype ) ?> $doctype(string) (optional) The type of html document 'xhtml' or 'html'.Default: 'html‘
Return Values
(void) This function does not return a value.Examples
<!DOCTYPE html> <html <?php language_attributes(); ?>> <head>
function language_attributes( $doctype = 'html' ) {
echo get_language_attributes( $doctype );
}
Uses: get_bloginfo() May call to get 'text_direction' or 'language'.
$bloginfo = get_bloginfo( $show, $filter );
bloginfo(string $show)
Display information about the blog.
Parameters: string $show What to display.
$show(string) (Optional) Blog info to retrieve.
Default value: ''
$filter(string) (Optional) How to filter what is retrieved.
Default value: 'raw‘
Return: (string) Mostly string values, might be empty.
Source file: wp-includes/general-template.php
get_bloginfo( string $show = '', string $filter = 'raw' )
esc_url ( string $url, array $protocols = null, string $_context = 'display' )
Checks and cleans a URL.
A number of characters are removed from the URL. If the URL is for displaying (the default behaviour) ampersands are also replaced. The ‘clean_url’ filter is applied to the returned cleaned URL.
Return: (string) The cleaned $url after the 'clean_url' filter is applied.
Source file: wp-includes/formatting.php
Parameters
$url(string) (Required) The URL to be cleaned.
$protocols(array) (Optional) An array of acceptable protocols. Defaults to return value of wp_allowed_protocols()
Default value: null
$_context(string) (Optional) Private. Use esc_url_raw() for database usage.
Default value: 'display'
get_template_directory_uri ()
Retrieve theme directory URI.
Return: (string) Template directory URI.
Source file: wp-includes/theme.php
<img src="<?php echo get_template_directory_uri(); ?>/assets/img/flexslider/flex-1.jpg" />If your assets folder inside theme.
<?php wp_head(); ?>
Fire the 'wp_head' action. Put this template tag immediately before </head> tag in a themetemplate (ex. header.php, index.php).
Parameters :-
This function does not accept any parameters.
Return values :-
None.
<?php ... /* Always have wp_head() just before the closing </head> * tag of your theme, or you will break many plugins, which * generally use this hook to add elements to <head> such * as styles, scripts, and meta tags. */ wp_head(); ?> </head>
wp_head() is located in wp-includes/general-template.php.
The wp_head action hook is triggered within the <head></head> section of the user's template by thewp_head() function. Although this is theme-dependent, it is one of the most essential theme hooks, so it is widely supported.
This function is simply a wrapper for:
function wp_head() {
/**
* Print scripts or data in the head tag on the front end.
*
* @since 1.5.0
*/
do_action( 'wp_head' );
}
This hook provides no parameters. You use this hook by having your function echo output to the browser, or by having it perform background tasks. Your functions shouldn't return, and shouldn't take any parameters.
This hook is theme-dependent which means that it is up to the author of each WordPress theme to include it. It may not be available on all themes, so you should take this into account when using it.
This hook is an action which means that it primarily acts as an event trigger, instead of a content filter. This is a semantic difference, but it will help you to remember what this hook does if you use it like this:
<?php add_action('wp_head', 'your_function'); ?>
Add custom css within head section using wp_head action.
add_action('wp_head','hook_css'); function hook_css() { $output="<style> .wp_head_example { background-color : #f1f1f1; } </style>"; echo $output; } Add custom javascript within head section using wp_head action.
add_action('wp_head','hook_javascript'); function hook_javascript() { $output="<script> alert('Page is loading...'); </script>"; echo $output; }
wp_head action hook is located in wp-includes/general-template.php
<body <?php body_class( $class ); ?>>
Themes have a template tag for the body tag which will help theme authors to style more effectively with CSS. The Template Tag is called body_class. This function gives the body element different classes and can be added, typically, in the header.php's HTML body tag.
class(string or array) (optional) One or more classes to add to the class attribute, separated by a single space.Default: null
Source file: wp-includes/post-template.php
function body_class( $class = '' ) {
// Separates classes with a single space, collates classes for body element
echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
}
<?php is_front_page(); ?>
This Conditional Tag checks if the main page is a posts or a Page. This is a boolean function, meaning it returns either TRUE or FALSE. It returns TRUE when the main blog page is being displayed and theSettings->Reading->Front page displays is set to "Your latest posts", or when is set to "A static page" and the "Front Page" value is the current Page being displayed.
Parameters :-
This tag does not accept any parameters.
If you are using a static page as your front page, this is useful:
<title> <?php bloginfo('name'); ?> »
<?php is_front_page() ? bloginfo('description') : wp_title(''); ?> </title>
Usage in a Custom Function
Added to your themes functions file, this code includes the is_front_page() conditional tag after the function name so the content only displays on the front page.
add_action( 'loop_start', 'using_front_page_conditional_tag' ); function using_front_page_conditional_tag() { if ( is_front_page() ) { echo'<h2>Only Displays On The Front Page</h2>'; } }
Source File
is_front_page() is located in wp-includes/query.php.
<?php is_home(); ?>
This Conditional Tag checks if the blog posts index page is being displayed. This is a Boolean function, meaning it returns either TRUE or FALSE.
with is_home() applying to the blog posts index, and is_front_page() applying to the site front page.
Be careful not to confuse the two query conditionals:
On the site front page, is_front_page() will always return TRUE, regardless of whether the site front page displays the blog posts index or a static page.
On the blog posts index, is_home() will always return TRUE, regardless of whether the blog posts index is displayed on the site front page or a separate page.
Whether is_home() or is_front_page() return TRUE or FALSE depends on the values of certain option values:
get_option( 'show_on_front' ): returns either 'posts' or 'page'
get_option( 'page_on_front' ): returns the ID of the static page assigned to the front page
get_option( 'page_for_posts' ): returns the ID of the static page assigned to the blog posts index (posts page)
When using these query conditionals:
If 'posts' == get_option( 'show_on_front' ):
On the site front page:
is_front_page() will return TRUE
is_home() will return TRUE
If assigned, WordPress ignores the pages assigned to display the site front page or the blog posts index
If 'page' == get_option( 'show_on_front' ):
On the page assigned to display the site front page:
is_front_page() will return TRUE
is_home() will return FALSE
On the page assigned to display the blog posts index:
is_front_page() will return FALSE
is_home() will return TRUE
is_front_page() returns true if the user is on the page or page of posts that is set to the front page on Settings->Reading->Front page displays
So if you set about us as the front page then this conditional will only be true if showing the about us page.
is_home() return true when on the posts list page, This is usually the page that shows the latest 10 posts.
If the settings under Front page displays are left at default then the home page will return true for both is_front_page() and is_home()
An example of using is_home():
You have set your posts page to a page called News.
A user navigates there and in the header you want to show additional navigation
You could use is_home() to do this.
Source File :-
is_home() is located in wp-includes/query.php.
get_sidebar ( string $name = null )
Load sidebar template.
Includes the sidebar template for a theme or if a name is specified then a specialised sidebar will be included.
For the parameter, if the file is called “sidebar-special.php” then specify “special”.
Source file: wp-includes/general-template.php
Left and Right SidebarsTwo sidebars in one theme.
<?php get_header(); ?>
<?php get_sidebar( 'left' ); ?>
<?php get_sidebar( 'right' ); ?>
<?php get_footer(); ?>
The file names for the right and left sidebars should be sidebar-right.php and sidebar-left.php respectively.
File name : index.php
<?php get_header( $name ); ?>
get_header ( string $name = null )
Load header template.
Includes the header template for a theme or if a name is specified then a specialised header will be included.
For the parameter, if the file is called “header-special.php” then specify “special”.
Includes the header.php template file from your current theme's directory. If a name is specified then a specialised header header-{name}.php will be included.
If the theme contains no header.php file then the header from the default theme wp-includes/theme-compat/header.php will be included.
Source file: wp-includes/general-template.php
get_header is a hook that gets run at the very start of the get_header function call. If you pass in the name for a specific header file, like get_header( 'new' ), the do_action will pass in the name as a parameter for the hook. This allows you to limit your add_actioncalls to specific templates if you wish. Actions added to this hook should be added to your functions.php file.
Note: This hook is best to use to set up and execute code that doesn't get echoed to the browser until later in the page load. Anything you echo will show up before any of the markup is displayed.
Example
The following example will enqueue stylesheets conditionally for a different headers. This is just one example of how you may use the hook, and will use a secondary template file of header-new.php
function themeslug_header_hook( $name ) {
if ( 'new' == $name ) {
add_action( 'wp_enqueue_scripts', 'themeslug_header_style' ); } }
add_action( 'get_header', 'themeslug_header_hook' ); function themeslug_header_style(){
wp_enqueue_style( 'header-new-style', get_template_directory_uri() . '/css/header-new.css' ); }
Multiple Headers
Different header for different pages.
<?php if ( is_home() ) : get_header( 'home' ); elseif ( is_404() ) : get_header( '404' ); else : get_header(); endif; ?>
<?php have_posts(); ?>
This function checks to see if the current WordPress query has any results to loop over. This is a boolean function, meaning it returns either TRUE or FALSE.
As a side effect, have_posts starts, steps through, or resets The Loop. At the end of the loop, have_posts returns 0 after calling rewind_posts.
This function does not accept any parameters.
<?php if ( have_posts() ) :
while ( have_posts() ) :
the_post(); // Your loop code
endwhile;
else : echo wpautop( 'Sorry, no posts were found' );
endif; ?>
Source File
have_posts() is located in wp-includes/query.php.
do_action ( string $tag, mixed $arg = '' )
Execute functions hooked on a specific action hook.
This function invokes all functions attached to action hook $tag. It is possible to create new action hooks by simply calling this function, specifying the name of the new hook using the $tag parameter.
You can pass extra arguments to the hooks, much like you can with apply_filters().
Source file: wp-includes/plugin.php
Parameters :-
$tag(string) (Required) The name of the action to be executed.
$arg(mixed) (Optional) Additional arguments which are passed on to the functions hooked to the action.
Default value: ''
Execute functions hooked on a specific action hook.
This function invokes all functions attached to action hook $tag. It is possible to create new action hooks by simply calling this function, specifying the name of the new hook using the $tag parameter.
You can pass extra arguments to the hooks, much like you can with apply_filters.