Add category to body class

This late in the process you should be able to rely on context set up, even outside of loop. On top of my head something like this should work: $categories = wp_get_post_categories( get_the_ID(), [ ‘fields’ => ‘names’ ] );

WordPress Ajax Callback

It looks odd to me that your ajax_shortcode_function() registers and enqueues your ajax script. According to the codex, you should register/enqueue in functions.php. Additionally, if you only need the url to ajax-admin.php, the tutorial says you can use the global ajaxurl variable and therefore you don’t need to localize your script. The other thing that … Read more

How to link a Page with an anchor tag in WordPress

Actually the problem was with my page settings. If someone wants to link a php file to another php file by anchor tag (a href=”https://wordpress.stackexchange.com/questions/239574/….”) and wants to send some data through URL, he/she must has to make the targeted php file a page template. Like this <?php /*** Template Name: Gallery ***/ Then he/she … Read more

Attaching a pdf to Contact Form 7 e-mail via functions.php [closed]

I’ve found what’s been missing in the code. You have to add this also: add_filter( ‘wpcf7_mail_components’, ‘mycustom_wpcf7_mail_components’ ); function mycustom_wpcf7_mail_components( $components ) { $components[‘attachments’][] = get_template_directory().’/pdf/test.pdf’; return $components; } Now everything is working fine and the file is attached to email without the need to add fields in the contact form.

Pass PHP variable to JavaScript without inline JS

Untested but gosh darn it might just work… javascript file: jQuery( document ).ready(function() { jQuery.ajax({ url: // !! hardcode the URL of WP admin-ajax.php here, since you don’t want to use wp_localize_script() to pass it in… type: ‘POST’, data:{ action: ‘some_action’, // this is the function (via wp_ajax_ hook) that will be triggered }, success: … Read more

Show price with Geo IP location

Here is a simple approach to achieve what you are trying. Put these functions in your theme’s functions.php or plugin file. This will let you capture 2-letter country code with API request. You have to test it remotely (if you test on localhost you’ll get no country code as your IP reads as 127.0.0.1, so … Read more

jQuery .each to get post meta and subtract from a sum

You don’t need to use jQuery for something like this, it would be better done if you just use php! So if you store those 3 values in variables you can then do basic math with that data about output the results. while ($query->have_posts()) : $query->the_post(); $tourNum1 = get_post_meta($post->ID, ‘tour_details_number’, true); $tourNum2 = get_post_meta($post->ID, ‘tour_details_number2’, … Read more

Do my defines need to be unique?

Yes they do, the more interesting question is why do you use define instead of const? Take a look here: define() vs const. The only situation in which you should use a define over const is if you want the user to be able to override your defines in wp-config.php. Obviously things like minimum php … Read more