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,664
questions
3
votes
2
answers
2k
views
Draggable item in custom gutenberg block
I'm developing some custom blocks in the new Gutenberg editor experience, and I'm struggle to understand how to use some build-in components, mostly the Draggable components.
What I would like to ...
0
votes
1
answer
2k
views
How to use wp-ajax in wp-cron
I have create a custom wordpress plugin where i am using wp ajax. In class's __construct i have an action (admin_footer) in order to use wp_enqueue_script and wp_localize_script following wp ...
0
votes
0
answers
23
views
How to pass php array to external js file in WordPress
I am trying to pass my php array to my external js file.
PHP
if (!function_exists('myScripts')) {
function myScripts() {
wp_enqueue_style('my-css', get_stylesheet_directory_uri() . '/...
0
votes
0
answers
26
views
How to replace Avatar link in profile page with upload profile pic. button using media library and display it in profile page and all wordpress site
I am developing a WordPress theme and using the following php code and JavaScript code, I replaced the Gravatar link with a button to upload profile image using Wordpress media library, the media ...
1
vote
0
answers
43
views
How to build BOTH non-block components and blocks present in the /src directory using @wordpress/scripts
I regularly use @wordpress/scripts for building both blocks and non-block components. Recently, I started working in a new plugin that registers both some blocks and non-block components that add ...
1
vote
1
answer
697
views
Force uppercase on some WooCommerce checkout fields input
I'm using this code to limit max number of characters to a determined field... is it possible to force UPPERCASE?
Here's what I'm using:
add_action("wp_footer", "cod_set_max_length");
function ...
0
votes
1
answer
1k
views
How to use posts as tabs in a custom page?
everyone. I'm a beginner at coding/Wordpress and need some help with a custom page I'm developing right now. The idea is simple:
A list of items on the left
An image with a description below on the ...
0
votes
0
answers
29
views
Separate typography controls for titles and meta in a custom block?
I'm building a simple dynamic custom block that shows a list of posts of a custom post type.
JS:
import metadata from './block.json';
import './style.scss';
const { name } = metadata;
export const ...
0
votes
0
answers
23
views
Add div on query loop page change
I have a little bit of JS that is wrapping elements of a blog module in a div in order to be able to create a flexbox layout
$(document).ready(function() {
$(".et_pb_post").each(...
0
votes
0
answers
54
views
Utilizing Node.js for Server-Side Rendering for API Services in WordPress blogposts
I have a WP blog where each post requires a unique JS code from the server side (SSR).
How can I do this?
I tried creating new NodeJS on Cpanel option:-
But I'm getting 404 when requesting the Server ...
0
votes
2
answers
738
views
Display text of price (minus 20%) on every product page in a sentence.
We have loads of products on our woo commerce and are trying to automate a few things.
All our products are 20% off if you use our specific promo code.
So at the top of every product page there is a ...
0
votes
1
answer
1k
views
How to get current_user_id from wordpress in node js?
There is a website on wordpress, in the plugins folder I have a project on Node js. In index.html (the client part, mostly js there), there is content that I have to show only to registered users. I ...
14
votes
2
answers
5k
views
When does Wordpress wrap inline scripts in CDATA?
I'm debugging a problem with a third party script of ours that wordpress users use by copy / pasting a snippet of script and html into their post's bodies like (non-real world example of course):
<...
1
vote
1
answer
368
views
Why is the Gutenberg editor not recognizing my updates?
I'm currently working on a Gutenberg block that includes a toggle control to hide or show content. I'm following the WordPress developer documentation, and the block behaves correctly when I toggle ...
0
votes
0
answers
71
views
Embedded data and the _fields parameter in getEntityRecords
I'm using the following code to retrieve a list of post of a custom post type named movie:
const { posts, hasPostsResolved } = useSelect(select => {
const query = {
order: 'desc',
...
1
vote
1
answer
23
views
Javascript functions not running
I am working on creating a plugin. The first thing I do is enqueue my css and javascript files. If I view the page source, I am seeing both files loaded. The problem I am having, is I have some ...
0
votes
0
answers
33
views
404 error on page reload
I have created a WordPress based web app that will rely on template pages that will host some vue.js different front-end apps. I've added this code to the theme functions file to rewrite all the ...
2
votes
0
answers
130
views
Gutenberg move post/page title to Editor sidebar document panel
I have not liked the way that the post/page title in Wordpress 6 / Gutenberg is contained directly in the block editor. I have found many ways to remove it with filters and / or restyle it but ...
0
votes
1
answer
57
views
Implement AJAX 'load more' with offset posts
I am trying to implement 'Load More' functionality via a button in a WordPress theme.
We are starting by displaying the first five posts using pre_get_posts in the standard WordPress query and, when ...
1
vote
0
answers
18
views
Keep the expansible tree (list of posts) open in the sidebar
I have created a plugin to diplay a list of posts (cpt) in a tree on the sidebar. It adds an icon [+] when posts have children. However when I click on a post the tree colapses. How can I keep the ...
1
vote
0
answers
156
views
How to add new ACF repeater row after removing all rows using jQuery/Javascript
I am creating a custom ACF Field within a page edit screen which I have added a div container, outside the container is 3 buttons. Add text block, add image and save.
I also have a repeater field (I ...
1
vote
2
answers
3k
views
create timestamp links to jump to specific times on rumble videos
I am trying to allow visitors to seek specific times on the embed rumble video inside the wordpress post by clicking to timestamp links. I can do it for youtube videos using Skip to Timestamp plugin ...
0
votes
1
answer
53
views
opening and closing elementor-widget-container
I want the following and hope you can help, I have created a container in Elementor and within this container I have added element and direction row.
I want to the container to toggle with a button ...
0
votes
1
answer
535
views
Manipulating the allowed inner blocks of a core-gutenberg-block?
I had special requirements for a Button-Block for the Gutenberg-Editor, so I built a custom block "myproject/button".
Now I try to use the core/buttons block with this new button block, but ...
0
votes
0
answers
32
views
Script tags stripped when using presto video player in WP Courses single lesson page
I am using presto video player for lessons of courses on my website created with the plugin WP Courses. Unfortunately in some pages WP Courses uses ajax and this is maybe causing the javascript script ...
0
votes
1
answer
72
views
Create Youtube embed block with createBlock
I was trying to use this to create a Youtube video block using JavaScript:
// Define the YouTube video URL (replace with your desired URL)
const youtubeVideoURL = 'https://youtu.be/NNrj0N-yTnM';
// ...
0
votes
1
answer
131
views
How to use webpack in WordPress theme? I want some scripts to load in the footer, some in the header and some with script parameters
I wonder how to use webpack while bulding theme for WordPress the correct way.
Everything is pretty easy until I have to make some unusual things.
So in the most simple scenario I just have some JS ...
1
vote
2
answers
668
views
Widgets and Post/Page edit/new blank, console errors only, no server errors
My post edit, post create, page edit, page create are completely blank pages (no WordPress navigation bar, no top admin bar). My widget page has the top admin bar and side navigation, but the rest of ...
0
votes
0
answers
41
views
How to make Contact Form 7 work when injected via AJAX in WordPress?
I am working on a WordPress project where I need to use Contact Form 7 as part of an AJAX response to check if certain data is available. However, I am facing an issue where the form is not working as ...
0
votes
0
answers
39
views
How to add icon to WooCommerce add to cart button
in woocommerce, I want to add an icon from the iconify library to the add to cart button of my site I made some attempts, but I did not get the desired result. I used WooCommerce hooks, but this icon ...
0
votes
0
answers
55
views
Does wp i18n CLI has a prototype of "update-json" file?
I correctly internationalized a javascript file from wp theme folder.
Now I would like to know if Wordpress team plans to propose a CLI to update json without losing existing translation.
It seems ...
2
votes
1
answer
239
views
Javascript localization doesn't load. How to Internationalize javascript without plugin?
The internationalisation of my theme is defined in functions.php and the javascript file to be internationalised uses the wp-i18n library.
The translation function __('string',text-domain'); is ...
0
votes
0
answers
26
views
TinyMCE - Unable to load the editor in vue front-end plugin page
I have this code in my plugin page that is created using vue 3.
I need to use the wordpress editor and I'v used the wp_enqueue_editor() function to load all the needed assets of tinyMCE.
in the vue ...
0
votes
1
answer
254
views
Include Block Variation Within InnerBlocks
I'm registering two block variations; one for query-loop (called carousel) and one for group (called dialog). Is it possible to include the variation for group/dialog inside the query-loop/carousel.
...
0
votes
0
answers
16
views
Is It Possible to Block Redirect Checker Tools from Knowing Where URLs are Redirected?
I want to block URL Redirect Chain Checker tools such as wheregoes(.)com. Is it possible to do it?
For example: wheregoes com/trace/20234194180/ this url can easily tell people where my affiliate link ...
0
votes
0
answers
24
views
unable to find the document body in user-edit admin using javascript or CSS
I am pretty new to using js on wp and I have this pretty tame script that is supposed to find the element and replace it using textContent. I also am using a simple CSS element that has the same ...
15
votes
5
answers
14k
views
Trigger Javascript on Gutenberg (Block Editor) Save
So I have a metabox which I want to trigger some Javascript when a post is saved (to refresh the page in this use case.)
In Classic Editor, this can be done via a simple redirect hooked to save_post ...
2
votes
2
answers
5k
views
Add confirmation popup on “Move to Trash”
I want to open javascript message "Are you sure you want to move the post to trash?"when we clicks on "Move to Trash" link in Publish box.
and when we click to OK the post go to trash or cancel to go ...
6
votes
1
answer
432
views
RequireJS in custom theme. Working Example
I try to add to my custom wordpress Theme requirejs because I do not want to use wp_enqueue over and over to inject used plugins and on the other side I do not want to mess the DOM from the beginning.
...
0
votes
0
answers
18
views
difference between code for admin, user facing (css, js)
So I have two pages, user-edit.php in the admin and a page for members to edit their own profiles. There is a group of section on both that has the same coding, the same css id's, the same classes, ...
1
vote
0
answers
38
views
How to access current discussion settings in gutenberg via JS?
We're struggling with the issue that occasionally comments are disabled for a post though the editors never manually change this option in Gutenberg (comments are enabled in global settings).
As a ...
0
votes
0
answers
25
views
Separating HTML and PHP from the Script?
So I have this code which makes the infinite scrolling effect in WordPress.
It fetches the title and read more correctly.
The problem I find with this code is when I want to insert complex code that ...
23
votes
5
answers
18k
views
Can WordPress be made to support websockets?
Websockets are a cool, cutting-edge technology wrapped into HTML5. Basically, you can open a websocket to enable persistent, 2-way communication with a web server. The client (user interface) can ...
0
votes
0
answers
14
views
Identify and style the paragraph beginning w/o a class: based on a combination of common characters (CSS, JS)
There are html-constructions: <p>— Some random text.</p>. Without class.
According to the specified attribute "dash, space, some random text.", I need to catch this condition and ...
0
votes
0
answers
23
views
Programmatic replacement of Publish date with Modified date does not work outside the_content area
I am having a problem replacing the Publish date with the Modified date when the theme is created using Avada Theme Builder.
The following code works fine on a theme created with Elementor:
add_filter(...
0
votes
1
answer
663
views
How do I add a class to Customizer preview based on class of Customizer control? (Customizer Javascript API)
I am pretty weak with understanding the Customizer javascript API but I am trying. I have done a few things but now I need to send data to the Customizer preview based on the click of a control in the ...
0
votes
1
answer
34
views
How to add a css class to postTitleWrapper in Gutenberg?
while working with react/JS is slowly getting easier, at times I'm still surprised why things don't work as I expect them to. Here, I'm trying to add a class to the '.edit-post-visual-editor__post-...
0
votes
1
answer
35
views
Giving each loop post unique numbers so that Wordpress would treat separately
So I got this code right now.
The problem I get is that it executes only for the first video.
I know I need to give each loop post a unique number in order for WordPress to treat them separately. Same ...
0
votes
0
answers
32
views
I need to optimize a website and I want it to import the js libraries only when I need themL
My problem is that I need to optimize a website, one of the ways is by removing that JS that is not used in the page, the website is quite large, I have managed to remove that JS that is not used but ...
6
votes
4
answers
20k
views
Where and how to put inline js in pages
On the Web there are many articles on how to insert external scripts into a document using the wp_enqueue_script() method.
Among the articles I couldn't find anything explanaining how to add inline, &...