Display current user metadata on WordPress page

You can try below snippet of code. i have develop shortcode you can take reference from it. function current_user_data_func( $atts ) { extract( shortcode_atts( array( ‘metakey’ => ”, ‘user_field’ => ”, ), $atts) ); ob_start(); if(is_user_logged_in()) { $current_user = wp_get_current_user(); $c_user_id = $current_user->ID; if(!empty($metakey)) { $value = get_user_meta( $c_user_id, $metakey, true); echo $value; } if(!empty($user_field)) … Read more

Shortcode runs when editing page

I’ve faced a similiar situation on couple of occasions. In my case the shortcode getting rendered on the text editor was caused by the shortcode echoing instead of returning its content. As noted on add_shortcode Codex entry, Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should … Read more

Logout user if click on a custom page link

yes we make custom page as logout link on this way add this in function.php add_action( ‘init’, ‘log_out_user’ );function log_out_user() { global $wp; $url=”http://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’]; //get current page url if(!empty(get_current_user_id()) && $url == ‘example.com/logout’ ) //check if user is logged in and current page url { wp_logout(); //this will logout user $siteUrl = site_url(); //get site … Read more

How to create custom variables in wordpress

Have a look at the get_user_meta function. Assuming the litecoin address in the user’s profile is stored as user meta, with the key of litecoin_address you can output the link like so:- $litecoin_address = get_user_meta( get_current_user_id(), ‘litecoin_address’, true ); if( !empty( $litecoin_address ) ){ // maybe do some additional sanitation of the litecoin address here … Read more

Shortcode and get_template_part

Function get_template_part() load file only from theme directory (or child theme). There is no filter or action hook that would change this behavior. You will need to write your own get_template_part() variant to load files from the plugin directory (replace the locate_template() call from the original function). Or write an explicit: $query->the_post(); include plugin_dir_path( __FILE__ … Read more