Function Reference of Logout in wordpress

Default Usage

<a href="<?php echo wp_logout_url(); ?>" title="Logout">Logout</a>

Logout and Redirect to Current Page

If inside the loop you can use:
<a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>
Otherwise you must use:
<a href="<?php echo wp_logout_url( $_SERVER['REQUEST_URI'] ); ?>" title="Logout">Logout</a>

Logout and Redirect to Homepage

<a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout">Logout</a>

Logout and Redirect to Another Site

If you are using wp_logout_url to redirect to another site on logout (e.g. another subsite in a MultiSite network) you'll need to make use of the allowed_redirect_hosts filter

add_filter('allowed_redirect_hosts','allow_ms_parent_redirect');
function allow_ms_parent_redirect($allowed)
{
    $allowed[] = 'multisiteparent.com';
    return $allowed;
}

<a href="<?php echo wp_logout_url( 'http://multisiteparent.com' ); ?>" title="Logout">Logout</a>

How to display different links for logged in and logged out users?

<div class="fr">             
    <ul class="rss">                  
        <li><a href="http://example.com/go/wp-login.php">Support</a></li>                 
        <li><?php if (is_user_logged_in() ) { 
                echo " <a href=\"" . wp_logout_url() . "\" title=\"Logout\">Logout</a>";
            }else{ 
                echo " <a href=\"http://example.com/" title=\"Login\">Member Login</a>";
            } ?>
        </li>             
    </ul>         
</div> 

In case of redirecting you can use  wp_logout_url(home_url()) to redirect it to Homepage.


How to show cart items and cart total in woocommerce?

<?php global $woocommerce; ?>

<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>

How to hide class or div in cart and checkout page in wordpress woocommerce?

<script>

$(document).ready(function() {

  if( $("h2:contains('Cart Totals')").length) {
   
    $('.sticky').css('display', 'none');
 
  }

else if( $("h3:contains('Billing Address')").length) {

$('.sticky').css('display', 'none');
}
else
{
       $('.sticky').css('display', 'block');
}

});

</script>

How to add custom div to checkout page?

/* Add custom div to checkout page */
// Hook in

add_filter( 'woocommerce_before_order_notes' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!

function custom_override_checkout_fields( $fields ) {

    echo '<div id="customdiv">';

 echo '</div>';
return $fields;
}

How to get wordpress three latest posts in your custom template?

query_posts('post_type=post&posts_per_page=3&orderby=date&order=desc');
while ( have_posts() ) : the_post();
    echo '<table>
                                                <tr>
                                                                <td rowspan="2" height="200" width="200"></td>
                                                                <td><h2>';
                the_title();
                echo '</h2></td>
                                                </tr>
                                                <tr>
                                                                <td>';
                if ( has_post_thumbnail() ) {
                               
                  the_post_thumbnail(array(200,200));
                  echo '</td><td style="vertical-align: top;padding-left: 10px;">';
                }
                the_content();
                echo '</td>
                                                </tr>
                                </table>';
endwhile;

// Reset Query
wp_reset_query();

/* end */

How to Add Search Form in your Post with a WordPress Search Shortcode

function wpbsearchform( $form ) {

    $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
    <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
    <input type="text" value="' . get_search_query() . '" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
    </div>
    </form>';

    return $form;
}

add_shortcode('amitworkdesk', 'wpbsearchform');


Now add [amitworkdesk] as a shortcode in anywhere you want the search bar.

How to make or create a table in SQL?

Query:

create table userquickprofile
(
id int(20) AUTO_INCREMENT,
name varchar(250),
email varchar(250),
role varchar(250),
age varchar(250),
sex varchar(250),
height varchar(250),
weight varchar(250),
heartrate varchar(250),
bodyweight varchar(250),
primary key(id));
)

Add welcome message in wordpress actions

To add a welcome message on the homepage:

<?php
function add_welcome_message(){
    if(is_home()) {
        echo '<div class="welcome-text">Welcome message</div>';
    }
};
add_action('themify_content_before', 'add_welcome_message');
?>
Then you need to add this to Theme > Styling > Custom CSS to style the .welcome-message class:
.welcome-text {
    padding: 15px;
    font-size: 120%;
    text-align: center;
}

Custom avatar support in wordpress?


Most people commenting on blogs online have an avatar associated with them. If, however, they don’t and you don’t particularly like the WordPress default avatar options, you can define your own.
To do so, include the following code in your functions.php:
if ( !function_exists('cake_addgravatar') ) {
 function cake_addgravatar( $avatar_defaults ) {
  $myavatar = get_template_directory_uri() . '/images/avatar.png';
  $avatar_defaults[$myavatar] = 'avatar';
  return $avatar_defaults;
 }
 add_filter( 'avatar_defaults', 'cake_addgravatar' );
}
What we’re doing here first, is checking to see if the function exists. If it does, we add a filter that tells WordPress to use our custom defined avatar as the default.
We are telling WordPress to find this avatar in our “images” directory inside the theme directory. Next step, obviously, is to create the image itself and upload it to the “images” folder.

Custome Menubar Support in wordpress


The navigation menu feature, introduced in WordPress 3.0, allows for the intuitive creation and maintaining of navigation menus in themes.
At the very least, a standard theme will need a main navigation menu, perhaps in the header and a secondary navigation menu in the footer. To do this, we will register those two menus “Main Menu” and “Secondary Menu”
While this isn’t a particularly new feature, its still nice to wrap it in an if function_exists() just in case the user is stuck in a pre 3.0 installation:
In the functions.php file, include the following:
if ( function_exists( 'register_nav_menus' ) ) {
 register_nav_menus(
  array(
    'main_menu' => __( 'Main Menu', 'cake' ),
    'secondary_menu' => __( 'Secondary Menu', 'cake' ),
  )
 );
}
Now that the Menus are registered, we need to tell the theme where to output them. We’d like the Main Menu to appear in our header. So, in our header.php file, we include the following code:
<?php if ( has_nav_menu( 'main_menu' ) ) { ?>
 <?php $defaults = array(
   'theme_location'  => 'main_menu',
   'menu'            => '', 
   'container'       => false, 
   'echo'            => true,
   'fallback_cb'     => false,
   'items_wrap'      => '<ul id="%1$s"> %3$s</ul>',
   'depth'           => 0 );
   wp_nav_menu( $defaults );
 ?>
<?php } else { ?>
 <ul>
   <?php wp_list_pages('title_li='); ?>
 </ul>
<?php } ?>
First, we check to see if we have a menu called ‘main_menu’ defined and if we do, we insert its contents here, otherwise we fallback to the default wp_list_pages() which we can further customize to display the links as we need.
If you’d like even further customization of the menu, see the WordPress codex page on wp_nav_menu() function.
We want the secondary menu to appear in the footer, so we open up the footer.php and include the following code:
<?php if ( has_nav_menu( 'secondary_menu' ) ) { ?>
 <?php $defaults = array(
   'theme_location'  => 'secondary_menu',
   'menu'            => '', 
   'container'       => false, 
   'echo'            => true,
   'fallback_cb'     => false,
   'items_wrap'      => '<ul id="%1$s"> %3$s</ul>',
   'depth'           => 0 );
   wp_nav_menu( $defaults );
 ?>
<?php } else { ?>
 <ul>
   <?php wp_list_pages('title_li='); ?>
 </ul>
<?php } ?>

Displaying Common Information using common functions in wordpress?


Now let’s move on to some more functions we can use inside the loop. Many of these functions can only be used inside the loop and may not work if used outside of it.
Display the title of the post:
<?php the_title(); ?>
Display the URL of the post:
<?php the_permalink(); ?>
Display the content of the post:
<?php the_content(); ?>
Display the excerpt of the post:
<?php the_excerpt(); ?>
Display the category of the post:
<?php the_category(); ?>
Display the tags used in the post:
<?php the_tags(); ?>
Display the time the post was published (uses PHP date formatting as a parameter):
<?php the_time(); ?>

How to get the url of current theme?

Getting the URL to the Current Theme

To grab the current theme directory’s URL, you can use the template_url parameter. This makes your WordPress themes more flexible so that when you change the domain name or use it in multiple domain names you don’t have to worry about changing anything that references the theme’s location. You can use this parameter a number of ways, such as for referencing custom external stylesheets, images, and JavaScript libraries that are inside the theme directory.
<?php bloginfo('template_url'); ?>

How to add google analytic code in wordpress?

1.<?php
2.add_action('wp_footer''add_googleanalytics');
3.function add_googleanalytics() { ?>
4.// Paste your Google Analytics code here
5.<?php } ?>



paste this code in your theme function file  (default: function.php)

How to get a site url in Wordpress code?

Getting the Site’s URL

Let’s say your site’s URL is http://example.com. If you want to print this out in the source, you can use the url parameter.
<?php bloginfo('url'); ?>
This works great for absolute link references. For example, if you wanted to reference your logo (let’s say the file name is logo.png) that is in a directory called images, you would do the following:
<img src="<?php bloginfo('url'); ?>/images/logo.png" />
The above outputs:
<img src=" http://example.com/images/logo.png" />