Last updated posts shortcode in functions.php

You can do this like bellow // register shortcode add_shortcode(‘last-modified’, ‘last_mofied_shortcode_callback’); function last_mofied_shortcode_callback() { $output=”<ol class=”list-numbered”>”; $recently_updated_posts = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => ’13’, ‘orderby’ => ‘modified’, ‘no_found_rows’ => ‘true’ // speed up query when we don’t need pagination ) ); if ( $recently_updated_posts->have_posts() ) : while( $recently_updated_posts->have_posts() ) : $recently_updated_posts->the_post(); $output … Read more

Function to function shortcode help [closed]

Not sure what you would need this for but this is how you take the data of the variable $result from the operation function to your shortcode: operation(); function operation(){ $result=5+1; return $result; } function my_function(){ $result = operation(); return (string)$result; } add_shortcode( ‘my-shortcode’, ‘my_function’ );

Display a custom name when the user has no name settle in his account

Use PHP ternary comparsion operator to check if get_user_meta() function returns blank or non-blank result: function colaborador_nome($atts) { if (is_user_logged_in() && !is_feed()) { return ‘&nbsp;’. (get_user_meta( get_current_user_id(), ‘first_name’, true ) ?: “Hi >No Name<, please settle your name in your account.”); } } add_shortcode(‘colaborador_nome’, ‘colaborador_nome’);