New answers tagged

0

You absolutely did not understand how the code from my previous answer works, yeah? The PHP ternary operator $result = $a ? $b : $c works the same way as the following construction: if ( $a ) { $result = $b; } else { $result = $c; } So the whole idea was to check if the get_user_meta(get_current_user_id(), 'last_name', true) function returns an ...


0

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.")...


0

You should use output control functions if you want to do it this way: function cotizador_shortcode($atts) { ... your code here ... ob_start(); ?> <!-- THE CODE BELOW SHOULD APPEAR IN THE PAGE CONTENT AS A TABLE --> ... HTML here ... <?php $output = ob_get_contents(); ob_end_clean(); return $output; } add_shortcode('...


0

The issue here is that both the functions have the same name - colaborator_avatar(). Make sure that $new_user contains the current user. Else use get_current_user_id() like this: get_user_meta( get_current_user_id(), 'first_name', true ); Show avatar and first name: // show user avatar if logged in function colaborator_avatar($atts) { if (...


0

I searched for 'wordpress get name of logged in user' and the first result gave wp_get_current_user, which will show logged in user first name. Examples of how to use from that page: $current_user = wp_get_current_user(); /* * @example Safe usage: $current_user = wp_get_current_user(); * if ( ! ( $current_user instanceof WP_User ) ) { * return; * } ...


0

The code exactly as you put it in your question works fine for me and does exactly what you suggested. To make it work I had to make sure my WP post editor was in code editor mode as HTML or Visual Editor may create extra problems: And this is what my test code in the post editor looked like, when I had a successful test: <!-- wp:html --> <p>...


0

Welcome to WordPress Development StackExchange site! In general you understand everything right, but there can be one important caveat: if some page content like page header, navigation menu, etc is already sent to the user, a try to set cookie from PHP script will give a following error: "Cannot modify header information – headers already sent by...&...


-1

Do you mean something like this? function some_function( $a ) { return $a * 2; } function my_shortcode( $atts ) { $params = shortcode_atts( array( 'value' => 0 ), $atts ); return (string)some_function( $params['value'] ); } add_shortcode( 'my-shortcode', 'my_shortcode' ); When you use [my-shortcode value=2] on your page, it would ...


1

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' );


0

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', '...


0

Use the ABSPATH constant defined in the wp-config.php: $filename = ABSPATH . 'wp-content/uploads/webcam/webcamimage.jpg'; You don't have to use basename() function since it would return only the last component from the full file path, i.e. webcamimage.jpg, and it isn't what you want to use with filemtime() function.


1

You have several options, but I would advise against what you're doing, what you really need is to make a new shortcode that calls the plugins functions to achieve what you want ( or to use a plugin that provides a filter ): 1. Search Replace on the Post Content Hook into the_content filter, and do a string search replace on the content before it's processed ...


0

It looks like wp_list_categories($args) will output directly when you call it, which is why the output comes out in a weird place. and ideally what you need is to capture the output and return it, but luckily wp_list_categories allows you to do this with the 'echo' parameter. Try: $args['echo'] = FALSE; return wp_list_categories($args); Note the extra '...


2

So from the WP_Query page, I found this, which is like $args['name'] but for when you want to search for many slugs: post_name__in (array) – use post slugs. Specify posts to retrieve. (Will be available in version 4.4) I think this is maybe what you need? In that case you'd need to explode $atts['post'] on "," as you did, then pass that resulting ...


0

This works for me: add_shortcode( 'latest_post', 'latest_post_query_shortcode' ); function latest_post_query_shortcode( $atts ) { ob_start(); $atts = shortcode_atts( array( 'posts_per_page' => '', 'category' => array(), // defined as array here 'offset' => '', ...


0

I had the same problem, for me the solution was to add this code to theme. if ( !isset( $content_width ) ) $content_width = 550; More info https://www.wpexplorer.com/wordpress-oembed/ Hope it helps someone.


0

So you want the index numbers for the posts array returned by WP_Query ? Try this: if ( $manset_posts->have_posts() ) { foreach( $manset_posts->posts as $key => $value ) { // $key is the index number for each post } }


Top 50 recent answers are included