Need to put a script above tag in header.php – WP 5.7.1

As @Buttered_Toest mentioned, this snippet works well. (This code goes to functions.php) function futy_widget_footer(){ ?> <script> window.Futy = { key: ‘0000000000’ }; (function (e, t) { var n = e.createElement(t); n.async = true; n.src=”https://v1.widget.futy.io/js/futy-widget.js”; var r = e.getElementsByTagName(t)[0]; r.parentNode.insertBefore(n, r); })(document, ‘script’); </script> <?php } add_action(‘wp_footer’,’futy_widget_footer’);

WordPress template page name displayed on screen

If your template file doesn’t have the <?php tag at the top, you should add it. <?php /* Template Name: Exhibition – Pilgrims */ …is how the very top of your template file should look. Your sample should read like this. <?php /* Template Name: Exhibition – Pilgrims */ get_header(); ?> <div class=”container fadeIn perimeter”> … Read more

admin-ajax Firing Error 400 When Logged In

Did I set up that wp_ajax_nopriv_ hook wrong? No, you did not. But that hook is for logged-out or unregistered users only. For logged-in users, the hook is wp_ajax_<action>. So you just need to change the add_action(‘get_events’ in your code to add_action(‘wp_ajax_get_events’, and the error 400 would be gone: add_action(‘wp_ajax_get_events’, ‘get_events_func’); // for logged-in users … Read more

Hide a div when tags doesnt exist [duplicate]

You need to first get and check if there are any tags available, so something like this <?php if (get_tags()) : ?> <div class=”etichete”> <p><?php the_tags(); ?></p> </div> <?php endif; ?> You can also use !empty(get_tags()) but because if no tags are available it will return an empty array and an empty array is considered … Read more

echo something inside a shortcode

There are a few to do this: Using double quotes Don’t forget to escape the double quotes inside the string. global $post; echo do_shortcode(“[sc name=\”$post->post_name\”]”); Using sigle quotes global $post; echo do_shortcode(“[sc name=”$post->post_name”]”); Using sprintf global $post; echo do_shortcode( sprintf(‘[sc name=”%s”]’, $post->post_name) ); Using wp_sprintf global $post; echo do_shortcode( wp_sprintf(‘[sc name=”%s”]’, $post->post_name) ); Using heredoc … Read more

Illegal string offset in PHP function

You need to be validating a couple of parts about $filearray before you use it. There are some good suggestions in the comments, I think a couple of robust examples would serve you well too: Using empty() function wp_custom_attachment() { wp_nonce_field( plugin_basename(__FILE__), ‘wp_custom_attachment_nonce’ ); $html=”<p class=”description”>Upload your PDF here.</p>”; $html .= ‘<input id=”wp_custom_attachment” name=”wp_custom_attachment” size=”25″ … Read more

Show meta box only for default page template

If the “Default Template” option is selected from the Template dropdown, then WordPress will set the value of the _wp_page_template meta to default and not page.php, so that’s most likely the reason why your meta box is not showing/added. So I would use if ( in_array( $pageTemplate, array( ‘default’, ‘page.php’ ) ) ) instead of … Read more

Notice: Uninitialized string offset: 0 in social sharing mu-plugin

Your custom get_the_post_thumbnail_src() function returns a string and not an array, hence in the following code, $sb_thumb is not an array: $sb_thumb = get_the_post_thumbnail_src(get_the_post_thumbnail()); So the PHP notice in question occurred because you used $sb_thumb[0] in the following code, which appears twice in your wpvkp_social_buttons() function: $pinterestURL = ‘https://pinterest.com/pin/create/button/?url=”.$sb_url.”&amp;media=”.$sb_thumb[0].”&amp;description=’.$sb_title; And to get rid of the … Read more

Access a particular field in an array

Going by your array you could do something like this. This is the minimun code required to only get the medium size url The function that handles finding all medium urls function get_images_medium_urls (&$urls = [], $arr, $find = [‘medium’, ‘url’]) { foreach ($arr as $key => $value) { if ($key === $find[0]) $urls[] = … Read more