Add Codepen animation as Preloader to WordPress

1) In which location should I add the codepen html code? If you’re using a child theme, then for example, you could copy parent theme header.php file to your child theme directory and add the required html to that file after <head>. If you’re developing your own theme, then put the markup wherever you want … Read more

Shortcode from a function not working

If you refer to the documentation for add_shortcode, you need your function to return the content: function uniquetestfunction($attributes) { return ‘<div class=”my_class”>Test Element</div>’; } add_shortcode(‘uniqueshortcodename’,’uniquetestfunction’); You also used the wrong quotes in your add_shortcode line – stick with single ‘ or double ” quotes.

Disable plugin function to use my own

You can use remove_action() to remove a function from a specified action hook. Documentation remove_action( string $tag, callable $function_to_remove, int $priority = 10 ) This function removes a function attached to a specified action hook. This method can be used to remove default functions attached to a specific filter hook and possibly replace them with … Read more

AJAX button action in foreach

This is happening because you have click event firing on ID jQuery(‘#przyciskUlubione’).click(function() { The ID is always unique, there should never be more than one same ID in the HTML. You can achieve this using class. Assign the same class to all the buttons. Change your selector to class: jQuery(‘.przyciskUlubione’).click(function() { add value attribute or … Read more

WordPress Environment: Dynamic Page using shortcode – how to change the page name for sharing

So depending on your theme, you’ll need to take a different approach. By the sounds of it, you’re using a theme that adds WordPress theme support for title-tag e.g. twentynineteen. In this case, your code would look like this: function add_dynamic_title( $aTitleParts ) { if ( isset( $aTitleParts[ ‘title’ ] ) && $aTitleParts[ ‘title’ ] … Read more

Best way to use a large array in function

If it’s just a list of numbers, I’d suggest just saving them in a text file, with a number on each line. 110019 111222 112233 Then when you need the file, read its contents with PHP, and use preg_split() to turn it into an array: $file_path = plugin_dir_path( ‘postcodes.txt’, __FILE__ ); // Or wherever you’ve … Read more

Run a code only on theme activation only during first activation

What about using WordPress Options API to store a flag whether it is the first switch or not: https://codex.wordpress.org/Options_API <?php add_action(‘after_switch_theme’, ‘setup_theme_options’); function setup_theme_options () { if(get_option(‘first_theme_activation’) === false){ // Set a flag if the theme activation happened add_option(‘first_theme_activation’, true, ”, false); // stuff here only runs once, when the theme is activated for the … Read more

Counting Search results, and displaying the offset per page

I’m afraid you’re doing it a little bit wrong… Here are the problems: post_count field contains the number of posts being displayed and not the offset. wp_count_posts returns the number of posts globally, not in current query (so it will not be true for queries that have some filters). echo $post_count; . ‘-‘ . $post_count; … Read more

Woocommerce Email attachments not working – file not being attached

Apparently Woocommerce need a local path and not a URL to the file. In order to fix I used this: function attach_order_notice ( $attachments, $email_id, $order ) { // Only for “New Order” email notification (for admin) //if( $email_id == ‘new_order’ ){ $file_path = wp_upload_dir()[‘path’]; $file_name = get_field( ’email_file_attachment’, ‘options’ )[‘filename’]; $attachments[] = $file_path . … Read more