Questions tagged [javascript]
A client side scripting language useful for making interactive web sites. Questions about using JavaScript outside a WordPress context are off-topic but might be asked on Stack Overflow.
2,689 questions
0
votes
0
answers
13
views
How do I ensure that the URL parameters are updated correctly when multiple filters are applied
I am writing a product filter, and ran into this issue.
I have 2 different attributes of my product filter:
Tilt -- as a checkbox with "Yes" or "No", and Multibrand Compatible -- ...
-1
votes
0
answers
11
views
I just wanted to know whether it is possible to import a JSON file into Excel used to upload the Income-Tax Returns on the Indian IT Act website? [closed]
Being a Chartered Accountant from Ahmedabad, Gujarat,India, I have been filing Income Tax Returns of clients to the portal at incometax(dot)gov(dot)in. These are highly structured JSON files with near-...
0
votes
0
answers
16
views
button for resetting all the custom meta fields
I’d like to have a button to reset all the custom fields for the prices, the button should operate from the author (agency) edit page because I’d like to clean the prices of all the apartments (posts) ...
0
votes
0
answers
18
views
Add a React search box to blog home error - Cannot read properties of undefined (reading 'jsx')
I have followed a couple of tutorials online in the pursuit of adding a react component to my WP page.
I have gone over and over it for errors and I cant see what I must be missing, as the console ...
0
votes
1
answer
9
views
Can you open a media frame to sellect an attachment to associate with another attachment you are editing on an existing media frame?
I want to have a media frame that pops up on click of a button on an existing media frame.
This way I can associate another attachment with that attachment.
This question shows an example of you can ...
0
votes
1
answer
36
views
How to render initial posts on page load in a Gutenberg block using the Interactivity API?
I have the following code (view.js) for a Gutenberg block which uses the Interactivity API that renders posts when clicking a button:
import { store, getContext, getElement } from '@wordpress/...
0
votes
1
answer
28
views
Pass WP data to javascript
I'm using data attributes to pass product price calculation formula to javascript. Is it possible to pass it to javascript without being displayed in page source code?
0
votes
1
answer
55
views
Simple ajax request with Vanilla JS keeps given 400 Bad Request
I am new to Ajax and hope someone can help me with the following.
I am trying to make simple ajax test in wordpress, but getting al the time a 400 Bad request. I am really wondering why this is not ...
2
votes
2
answers
153
views
How to render HTML content using the Interactivity API?
I'm testing the new Interactivity API and want build a block that renders the title and content of a random post.
This is the content of the render.php file:
<?php
$block_attributes = ...
0
votes
1
answer
24
views
How to get selected category objects in the block editor?
I am using the following functions to get the selected category objects. It seems to always return no matches even though there are several. What am I missing here?
(function (wp) {
const { ...
0
votes
0
answers
27
views
Custom PHP contact form issue
I'm building a WP website with a custom contact form in PHP, HTML and Javascript.
The issue is when the user click the submit button to send the form, it redirects to a 404 page.
The PHP function:
...
0
votes
1
answer
100
views
Add Imports to Existing WordPress Import Map
How can imports be added to the existing WordPress import map?
Preparing the Module
I have a JavaScript module threeDTest.js which is enqueued using a PHP short-code (set to run everywhere):
...
0
votes
2
answers
70
views
How to auto rename JS files to prevent browser cache issues
Im creating a block plugin in worpress and each time I update my JS files, changes do not reflect to frontend because there's a browser cache.
I found some strategies in others frameworks that rename ...
0
votes
0
answers
24
views
Why does website not scroll to top of container when phone is rotated?
I'm using Elementor. I have a container that has a price list in it which looks terrible on mobile portrait. I used the responsive setting to hide that container on mobile portrait. Then I added a ...
0
votes
1
answer
29
views
Function to filter numbers from string
I'm looking to filter numbers from a string, and make them bigger in one case, and hide them in the other. The best way, as I understood, would be to use a custom function via functions.php and ...
0
votes
0
answers
15
views
How to display all submenu items as a breadcrumb
I'm trying to display all submenus of the active page as a breadcrumb navigation on a section of the page. How could I go about this?
For example;
Home
Program
P1
P2
P3
About
When I navigate to the ...
0
votes
2
answers
97
views
Elementor Form : client side javascript validation
I already did server side data validation using the hook 'elementor_pro/forms/validation' and it's working fine.
Now in addition, I would like to do client side data validation before submitting the ...
0
votes
1
answer
35
views
How to use useSelect to retrieve the currently default fontFamily?
I'm trying to identify where I could find this information but I've not been able til the present moment, to achieve it.
I've been looking in core/block-editor and core/editor. I've been researching ...
2
votes
0
answers
80
views
How to Use Webpack with WordPress Script Modules and Enqueue a Custom Class
I am working on a WordPress project using version 6.5, which introduced support for JavaScript modules. I have a parent theme that exports a JavaScript class, and I want to import this class in a ...
1
vote
0
answers
66
views
Extend WordPress Gutenberg core/navigation-link
Hey folks So Im pretty new to this react + php in wordpress and I found one article where it showed how to extend a core block, which works fine for group and some basic block but When i tried to ...
1
vote
1
answer
447
views
Add custom data attribute to every core Gutenberg Blocks
I'm adding two custom attributes to core Gutenberg blocks, data-delay and data-duration.
I want to add these attributes to manage animations blocks on my custom theme.
I wrote this JS code into block-...
2
votes
0
answers
43
views
Block style variations not enqueued for blocks inside HTML code dynamically rendered via JS
The new WP 6.6 will let anyone style any registered block style variations in theme.json via the styles.blocks.blockName.variations property. Check the following post for more info:
https://developer....
0
votes
0
answers
34
views
How do I expose the current logged in users name/etc to javascript?
Currently using a Javascript API for he first time to our woocommerce site. We have installed a chat (Social Intents) which provided us with a code to collect data from the person chatting with us. ...
0
votes
0
answers
23
views
Smooth Scrolling Animation of Image Between Two Containers (Elementor) Using JavaScript and GSAP
I am trying to achieve a smooth scrolling animation in Elementor where a Cola can image moves from one container to another container as the user scrolls down or up the page.
please see attached.
I am ...
0
votes
0
answers
10
views
Event when Modal is opened/visible
In my WordPress plugin, a Modal gets opened from within the Block Editor when a button is clicked.
const MyContent = () => {
const [isOpen, setOpen] = useState(false);
const openModal = () =...
0
votes
1
answer
113
views
how to escape alert/window.location.replace with variable
I'm trying to write my first WordPress plugin and despite reading the documentation about escaping and reviewing other people's questions and answers I'm still not clear on how to do it in 2 cases the ...
0
votes
1
answer
90
views
Is there a way to pull remotely generated XML, process it, and display it on a Managed WordPress page?
Note: This is cross-posted on stackoverflow.
I need to get some XSQL generated XML data from a remote server, process it, and display it on a GoDaddy Managed WordPress page. (This is the website my ...
0
votes
0
answers
29
views
Is there an existing method to store a large set of states (900+ flags/numbers) for a single form page that it can persist for several days?
I just need a pointer or two in the right direction. I made a WP page with a large set of checkbox items to mark a set of tasks as completed, with the intent to also implement counters for a few other ...
0
votes
0
answers
47
views
I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
//this is my functions.php
// Enqueue Styles
function meraboiler_enqueue_styles() {
wp_enqueue_style('google-fonts', 'https://fonts.googleapis.com/css2?family=Patua+One&family=Open+Sans:wght@...
0
votes
1
answer
58
views
Loading specific ajax from a product
I'm new to wordpress, and I need some way to define a property in a new product that will then have it load specific javascript code related to that specific type of product. I may need to load a ...
1
vote
1
answer
176
views
How to transform a shortcode into a block
I've built the following Gutenberg block. It's a carousel of images:
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
G,
Path,
SVG,
ToolbarGroup,
...
0
votes
0
answers
73
views
Start a long running PHP process via JS/Ajax and monitor progress on admin page
I am developing a plugin, which can import layouts for a certain theme from a remote URL. Those layouts often contain a good amount of images and sometimes even videos. I have a admin page where the ...
0
votes
0
answers
43
views
How to get selected variation from URL?
I create my own way of displaying the list of available variants on the product page.
I display individual variants on the main page of the store so that when the customer goes to the product page, he ...
0
votes
1
answer
104
views
Calling a function via a shortcode in javascript
I'm looking to dynamically change the page-comments option based on whether the user clicks a URL.
I have two functions to do this:
function psb_comment_listener_func(){
echo "
<...
0
votes
1
answer
37
views
How to apply a javascript code on certain parts of elementor made pages?
For example I have a simple animation which decreases the menu height and font-size while scrolling.
<html>
<head>
<script>
document.addEventListener("DOMContentLoaded", ...
0
votes
1
answer
86
views
Escaping inline JS correctly
function test_dashboard_content() {
$args = array( 'posts_per_page' => -1, 'post_type' => array( 'post', 'page' ), 'post_status' => 'publish', 'date_query' => array( 'after' => '1 ...
0
votes
1
answer
22
views
How can I access custom data fetched from posts in a javascript script?
I am trying to fetch the lat, long data from custom fields in my posts in order to make a map layer with them (openlayers).
I added custom long and lat fields to each post
I created a function to ...
2
votes
1
answer
222
views
Wordpress Gutenberg Custom Block the viewScript does not get loaded on the frontend when my block is inserted
I recently developed a custom Gutenberg block by utilizing the @wordpress/create-block package, which effectively generated a full plugin framework. I simply needed to tweak some existing files to get ...
1
vote
0
answers
187
views
Custom gutenberg block refuses to load viewScript and I don't know why
I've been struggling with this for hours. I used the @wordpress/create-block package to generate a template for me to create my first block. I've managed to create a hero block with an image uploader ...
3
votes
1
answer
268
views
How to add group-row to InnerBlock template?
We are trying to add a group-row to our InnerBlock template.
Now there is a core block called core/group which works when being inserted. The core/group has variations as group-row. But when inserted ...
0
votes
0
answers
46
views
add_attachment hook not firing on certain devices
I am developing a plugin for a client, and we are using the add_attachment hook to extract metadata from the images that we process as part of the plugin.
The funny thing is that the hook successfully ...
0
votes
0
answers
19
views
Retrive the value of the Active variation of the product and then link it to the "read more" to dynamically change
Here is the code snippet where Only the tab-description is attached to the "Read-more". How to make it dynamically change based on the current active value of the Variation - material ...
1
vote
1
answer
99
views
Can't make an external api call in php side of wordpress child theme
Edited 07-14-24 to show permission callback in api
Edit 2: showed my fatal error
I'm new to making api calls in wordpress. I need to make an api call through the backend to a 3rd party api. I can't do ...
0
votes
0
answers
62
views
Why is my JS not working on initial load?
I'm having weird issues with one of my JS Files that I added via a child theme. I have enqueued it in the functions.php and added some vars with wp_localize_script.
wp_enqueue_script('header-astra', ...
0
votes
0
answers
44
views
Additional CSS classes not being added in Gutenberg editor
When we add additional classes to our custom block they are not being added in the editor. When we save the block and view the front-end the additional classes are showing. But in the editor they won'...
0
votes
0
answers
68
views
Sudden ERR_HTTP2_PROTOCOL_ERROR on every JS and CSS files loads
I recently went on my website which is online since more than 5 years now and realized that none of the CSS and JS files were loading. By looking into the console, I’ve seen that every load fails ...
0
votes
0
answers
25
views
allow multi carousel in same page
I have this code for slider, i need help to edit it to allow multiple slider in same page.
var all_divs = $('.px-carousel-container .px-carousel-item').length;
var i = 0,
n = 0;
let ...
0
votes
2
answers
1k
views
window.location.href doesnt' work to redirect page
I am trying to add a custom HTML block to the page with the below code.
I created a Drop-down List and a search button for redirecting pages.
But it seems like that window.location.href doesn't work ...
1
vote
0
answers
95
views
slider i want move 4 images every button click
I have this code for slider button, i want move 4 images every button click. and make the button not active when all images slides if right or left. (sorry if my English not good)
$(document).on('...
1
vote
0
answers
16
views
can not serialize and insert data from custom form
I have a custom form . My form have three input fields book_name, chapter_title and chapter_content. chapter_title and chapter_content are dynamic form fields. I want to insert book_name as post_title ...