Shortcode just with a php code

It sound like you can accomplish this with 2 PHP functions. 1) Save the searched taxonomy to the user’s session. When they re-run the search function, update the taxonomy that was searched. This way if its saved to their session, you can use it elsewhere on the site just for that user. 2) Create a … Read more

Shortcode displaying outside the div [duplicate]

You could put all the html in a variable and return it $r = “<div id=\”” . $s[‘id’] . “\”…”; if (!empty($s[‘fb’])) { $r .= “<a href=\” . $s[‘fb’] . “…”; } $r .= “title=\”Follow Us On Facebook\” “; $r .= “target=\”_blank\” “; return $r; But every shortcode on your site should do this, for … Read more

Get shortcode attribute for AJAX call

The problem is ordering. $srcDir is being set correctly, but when it’s set the call to wp_localize_script has already happened. Instead, consider changing your code to refer to a data attribute in the content that the shortcode returns. This also prevents the code being tied to only allowing a single instance per page. Additionally, there … Read more

Add audio file to post using custom term meta field as link [closed]

I figured it out! Using this code I was able to use my custom meta field as the link in the audio shortcode. First I created a function in functions.php: function audio_link() { $terms = get_the_terms($post->ID, ‘taxonomy-name’); $result = “”; if (is_array($terms) || is_object($terms)){ foreach ($terms as $term) { $term_id = $term->term_id; $result .= get_term_meta( … Read more

create a shortcode for embedding google map in a page

function bartag_func( $atts ) { $atts = shortcode_atts( array( ‘latitude’ => ‘28.66’, // default value ‘longitude’ => ‘99.25’ // default value ), $atts, ‘bartag’ ); return <div class=”” latitude=” ‘.$atts[‘latitude’].’ ” longitude=” ‘.$atts[‘longitude’].’ “></div>’; } add_shortcode( ‘bartag’, ‘bartag_func’ ); Now you can use shortcode like : [bartag latitude=”12.34″ latitude=”12.34″] will return : <div class=”” latitude=”12.34″ … Read more

shortcode display metainformation as linked image

@WebElaine is correct. I had to use the wp_get_current_user(); and remove global. This is what worked for me function download_to_wallet() { $current_user = wp_get_current_user(); // get current user’s information $qr_url = $current_user->qrbase_code_pass_url; return ‘<a href=”‘. $qr_url . ‘”><img class=”qr_download” src=”https://example.com/wp-content/uploads/2018/08/add-to-apple-wallet-logo.png” style=”width:200px;”></a>’; }