wordpress use single ajax in place of multiple ajax requests in a smarter way

I appreciate your question is quite old and you no doubt already have your solution but hopefully this may help someone else. You could replace your javascript post calls with a single call to a single function that extracted both parts of data and returned them as an object. $(‘body’).on(‘change’,’#product_name’, function() { //Get product prices … Read more

if statement for wordpress default featured image on single post

So we have this: if ( is_home() ) { echo ‘<div id=”featured-image-home”><img src=”‘. get_stylesheet_directory_uri() . ‘/images/sample.jpg” /></div>’; } elseif ( is_singular( array( ‘post’ ) ) ! has_post_thumbnail() ){ echo ‘<div id=”featured-image-home”><img src=”‘. get_stylesheet_directory_uri() . ‘/images/blog-banner.jpg” /></div>’; } else ( is_singular( array( ‘post’, ‘page’ ) ) && has_post_thumbnail() ){ echo ‘<div id=”featured-image”>’; echo get_the_post_thumbnail($thumbnail->ID, ‘header’); echo … Read more

How to get_template_directory() properly on local environment

get_template_directory() returns a filesystem path– that is, it returns the path to the file as it would appear if you were browsing it on the local machine via a file browser. Return Values (string) Absolute path to the directory of the current theme (without the trailing slash). https://codex.wordpress.org/Function_Reference/get_template_directory That is what you are seeing. The … Read more

How to pass variables from a function in functions.php to an other one

get_the_utm_vars doesn’t work like you think it does. A function cannot return more than one value. Right now, when the first return is reached, that value is returned and none of the following lines are ever reached. You could have get_the_utm_vars return an array of values instead: function get_the_utm_vars(){ $utm = array(); $utm[‘source’] = htmlspecialchars( … Read more

It does not work concatenation in function.php

the_post_thumbnail() echoes data immediate, what you want to try is get_the_post_thumbnail() which returns data so that you may concatenate properly. WordPress core functions that are prefixed with the_ usually echo, those prefixed with get_ usually return. See: https://developer.wordpress.org/reference/functions/the_post_thumbnail/ https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/

Which function required?

Add <?php get_footer(); ?> into index.php or the template you are using Then create footer.php and add in something like this: <?php /* Always have wp_footer() just before the closing </body> * tag of your theme, or you will break many plugins, which * generally use this hook to reference JavaScript files. */ wp_footer(); ?> … Read more

Help With Creating Shortcode

It seems that extract() function sets it to false if value is not provided. There might be a better way around it, but I’ve used workaround as follows function Test($atts) { extract(shortcode_atts(array( ‘row’ => null ), $atts)); $output=”false”; if( in_array(‘row’, $atts)) $output=”true”; return $output; } add_shortcode(“test”, “Test”);

different style sheet for just one page template

The preferred way is to use add_action( ‘wp_enqueue_scripts’, ‘themeslug_enqueue_style’ ); within your child theme functions.php file or directly in your referral.php template page. Either way, it’s by using add_action and not by echoing into the <link> tag. Registering your style is also a recommended practice. The one benefit I would see in your case is … Read more