Count the number of times the search form template gets included on a page

Just few simple ideas: A) Here’s one suggestion using the get_search_form filter with a static variable to handle the instance counting: add_filter( ‘get_search_form’, function( $form ) { static $instance = 0; $instance++; // Setup your form here with the $instance variable as needed: $form = ‘<form>…</form>’; return $form; } ); B) Another workaround would be … Read more

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

Locating Global Variables

Child themes The WordPress Way of modifying the theme’s page-templates/front-page.php is to create a child theme, then duplicate this file in the child theme and make the modifications there. Your modified template file will be loaded instead of the parent theme’s file. This allows the parent theme to be updated without losing the modifications made … Read more

Getting RGBA colour from gutenberg colourpicker

If you mean wp.components.ColorPicker which is based on react-color, then the tint object also contains a rgb property with an object of the RGBA value like {r: 51, g: 51, b: 51, a: 1}. So in your code, you can use: style={{ backgroundColor: `rgba(${tint.rgb.r}, ${tint.rgb.g}, ${tint.rgb.b}, ${tint.rgb.a})` }} And an easy trick to know all … Read more

Add classname comment template from functions.php

You should consider hooking into the comment_class() and post_class() filters, if your theme supports it. Using the comment_class filter: We can add the following filter: /** * Add a custom comment class, based on a given comment author’s user meta field. * * @see http://wordpress.stackexchange.com/a/170443/26350 */ add_filter( ‘comment_class’, function( $classes, $class, $comment_id, $post_id ) { … Read more

How to get variables from fucntion.php to my plugin files

There is three way to use function.php file variable into plugin file. Using global. Make sure you globalize it first. global $my_variable; echo $my_variable; I recommend is using WordPress built-in filter mechanism add_filter. You add the filter in your functions.php file and apply it where needed. In functions.php: add_filter( ‘my_variable’, ‘return_my_variable’ ); function return_my_variable( $arg … Read more

Cannot get grandparent object

just a small error. To get the parent and Grandparent objects, you need to get_post them also. The property “post_parent” only gives you the ID of that post, not the post_object itself. So you change your code like this: <?php $current = get_post($post->ID); //Conditional to be sure there is a parent if($current->post_parent){ $grandparent = get_post($current->post_parent); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)