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.

965 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8 votes
2 answers
1k views

Pass media upload value to input field

I have created a meta-box that provides a upload function via the default media uploader from WordPress. This works fine as long as I have one upload option. But guess what? I want another one. If I ...
Interactive's user avatar
6 votes
0 answers
482 views

Gutenberg Blocks doesn't render correctly when using do_blocks

I'm trying to render a post_content with blocks using the do_blocks function, that takes a gutenberg content, parses every block, and returns an HTML string. The problem is that some blocks aren't ...
Raba's user avatar
  • 406
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. ...
fefe's user avatar
  • 874
5 votes
0 answers
777 views

Is there a core Sortable component in Gutenberg?

I managed to somewhat replicate the product gallery metabox from WooCommerce in Gutenberg using the third-party react-sortable-hoc component. As it seems that this component is no longer supported, I'...
leemon's user avatar
  • 1,888
5 votes
2 answers
2k views

How to refresh Theme Customizer after change color inside wpColorPicker?

I develop my custom widget with setting where I can set up custom color for the widget. I use this code to initialize wpColorPicker instead of default text input in form() method of Widget class: ...
Kolya Korobochkin's user avatar
4 votes
0 answers
895 views

Developing the save function in Gutenberg blocks

I am editing the save function on my local wordpress instance. Every time I make a change, I need to manually click the "Attempt Block Recovery" button to see the updated change when I go to ...
prawn's user avatar
  • 163
4 votes
0 answers
413 views

Custom Block - save.js function not saving attributes

I'm trying to get just a basic custom block displaying in the editor and saving. I've followed multiple tutorials and I keep getting the same result. No matter how simple my block is, whenever I add a ...
Ryan H's user avatar
  • 41
4 votes
0 answers
283 views

Provide specific example for block variation

I'm generating block variations on top of the "native" Gutenberg blocks (eg. core/***). For example, I have a "catchphrase" block, which is a variation of the paragraph block (core/...
corbin-c's user avatar
  • 141
4 votes
0 answers
1k views

Remove left alignment option in core/image block

I’m trying this code to disable the left alignment option from the core/image block. I just want to make available the center and right alignment options. wp.hooks.addFilter( 'blocks....
elvismdev's user avatar
  • 300
4 votes
0 answers
187 views

Hooking a callback into the code within a Gutenberg block

I want to run some JavaScript when a user uploads an image or images using the core/image block or core/gallery block. Ideally I would run my own code when the onSelectImage function is called (and ...
Sean's user avatar
  • 647
4 votes
1 answer
182 views

Detecting Wordpress Customizer Panel

Recently started developing a Wordpress theme relying heavily on the customizer API. One thing I'm stuck with is detecting when a specific panel has been clicked or opened. Regular old "on click" ...
user892670's user avatar
4 votes
1 answer
2k views

Looking for callback function after Gutenberg is rendered?

On post/page editing screen, I want to call my functions as soon Gutenberg editor/whole page is fully rendered and visible. On WP 5.2.2, I have tried jQuery(document).ready(function () {}); and wp....
M-R's user avatar
  • 2,606
4 votes
1 answer
683 views

Display message once per session to users with a specific role

I need to display a message to only users with a specific role. The message should appear either as soon as the user logs in or if they re-open their browser after having closed it when logged in to ...
user1462's user avatar
  • 1,284
3 votes
1 answer
364 views

InnerBlocks restricting does not work on nested blocks

I'm defining which set of blocks to allow in my custom innerblocks: const ALLOWED_BLOCKS = [ 'core/image', 'core/paragraph', 'core/group' ]; ... <InnerBlocks allowedBlocks={ ALLOWED_BLOCKS } />...
CyberJ's user avatar
  • 437
3 votes
0 answers
77 views

What is "open()" in MediaUpload?

Googling (or searching here) on "open" is hard :) The readme for MediaUpload gives this example: <MediaUpload onSelect={ ( media ) => console.log( 'selected ' + ...
philolegein's user avatar
3 votes
0 answers
608 views

WASM page in Wordpress website

I used emscripten to generate some html/js/wasm/data files and would like to add that as a page to my (Wordpress) website. Is this possible? If so, how?
cajomar's user avatar
  • 131
3 votes
0 answers
53 views

WordPress Rest API only returns content when posttype has editor capability

I am trying to request my post via the WordPress V2 Rest API in the backend. For whatever reason the post content is only returned when my custom post type has the editor support enabled. Is there a ...
Dhalucario's user avatar
3 votes
0 answers
373 views

WordPress Customizer Control with React

I am just doing a demo on the WordPress customizer API to edit the header with custom controls. I have designed a custom control by extending WP_Customize_Control and Jquery to refresh/postMessage ...
Rohit Patil's user avatar
3 votes
0 answers
105 views

How can I filter block registration based on post-type? (Block alignment settings)

I want to disable the .alignwide and .alignfull block alignment options (remove them from the editor UI) on the 'post' post-type only. I have tried using this block registration filter to modify the '...
ChemicalSailor's user avatar
3 votes
0 answers
233 views

How to save a ToggleControl value in a meta field?

I registered a boolean meta field called _meta_restrict in a custom post type: PHP: function register_meta_fields() { register_post_meta( 'custom_post_type', '_meta_restrict', array( '...
leemon's user avatar
  • 1,888
3 votes
0 answers
386 views

When using the block.getSaveElement hook can you output different markup based on whether or not you are in the edit view or the live page view?

I am trying to extend the core/image block to add an option for a deferred image. I want to replace the src attribute of the image with an empty string and add the url as a data attribute to be loaded ...
James Hamann's user avatar
3 votes
0 answers
254 views

Gutenberg - What is the best way to save/update post meta?

What would be the best way in Gutenberg to save/update post meta (not from a block). I can't find an API for it. I was thinking of doing some ajax in componentDidMount using wp.ajax.post Any advice ...
DonPotato's user avatar
3 votes
3 answers
2k views

Relative path instead of absolute for wp_enqueue_script

When you enqueue scripts or styles with the following: function themeslug_enqueue_style() { wp_enqueue_style( 'core', '/style.css', false ); } add_action( 'wp_enqueue_scripts', '...
Troy Templeman's user avatar
3 votes
1 answer
2k views

How to Use JSON With AJAX?

I've defined a PHP callback function to handle the communication between server-side and client-side: function json_render_modal_body() { check_ajax_referer( THEME_PREFIX . '-modals', 'nonce' ); ...
Michael Ecklund's user avatar
3 votes
1 answer
993 views

preserve url parameters from affliliate sites

Please help, I am using a wp site as medium between e.g. a news site lets call it A and the actual site that e.g. sells a particular product lets call it B. A ---- medium site --- B news site ---- ...
kan1's user avatar
  • 31
3 votes
2 answers
3k views

Customizer Show/Hide Logo and Site Title

I've setup checkbox controls in my theme Customizer to show/hide the Logo and Site Title when they are checked/unchecked. By default, I want the Logo to display and the Site Title to be hidden. ...
Troy Templeman's user avatar
3 votes
0 answers
46 views

Script won't execute in the media manager

I'm trying to execute a jquery script on the click of a button in a custom tab of the media manager, but it does not seem to work. I have been told this might be due to the button not being loaded ...
Slereah's user avatar
  • 131
3 votes
0 answers
624 views

Making a custom widget that includes a tinymce and works in Site Origin Page Builder

For a client I'm using Site Origins Page Builder plugin. It enables the client to make rich layouts for each page by dragging and dropping widgets. Site Origin widgets that require a WYSIWYG-editor ...
Wouter Vandenneucker's user avatar
3 votes
0 answers
189 views

How to create a repeatable / reusable divs in the metabox?

I have a meta box: <?php function custom_meta_box_markup() { global $post; $meta_box_text = get_post_meta( $post->ID, 'meta-box-text', true ); $meta_box_text_day = get_post_meta( $...
foolishcoder7721's user avatar
3 votes
1 answer
1k views

How to disable drag-and-drop upload function in Media Library?

Does any one knows a valid/standard way to disable drag and upload when accessing the media library in the admin area? In order to make this sense to you, I'm building a multisite and user of sub-site ...
Dbx's user avatar
  • 31
3 votes
0 answers
1k views

How to overwrite JS variable with wp_localize _script?

The function wp_localize_script( $handle, $name, $data ); does not work when trying to overwrite the same variable, that is when calling the function second time with the same $handle and $name but ...
progmastery's user avatar
3 votes
0 answers
314 views

Theme Customiser not live previewing changes on pseudo elements

I've been working with the Theme Customiser API lately and found that pseudo elements are not live updating using the previewer. In my project I have an image containing a transparent overlay using ...
Tim's user avatar
  • 198
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 ...
Kuuak's user avatar
  • 81
2 votes
0 answers
24 views

Can't find elemnts on the DOM using Custom Control in Customizer API

I'am creating a Custom Control on Customizer API, I add Multiple Checkbox as my custom type. When I wanna add a live preview, the jQuery doesn't find the selector that I want. Here's functions.php ...
Miminou's user avatar
  • 21
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 ...
Walrus's user avatar
  • 131
2 votes
0 answers
38 views

configure additonal build files in the @wordpress/create-block

I'm using the @wordpress/create-block package to create my block plugin. It comes with preconfigured webpack settings to build all the assets. By default as js in the src/ folder is built in the build/...
Will Honeywill's user avatar
2 votes
0 answers
95 views

Prevent posts from being published if the 'Uncategorized'-category or no category is selected

I do not want a user to be able to publish a post if no category is selected. This exact solution from a similar question is exactly what i want to do: jQuery(document).ready(function ($) { // ...
Joachim's user avatar
  • 21
2 votes
0 answers
465 views

Wordpress Gutenberg: Attribute overwritten by block duplicate

For a custom wordpress gutenberg block I've created a list of buttons so that users can add/remove as many as needed. While this works pretty fine one issue occurs: When duplicating a block the ...
Kristo's user avatar
  • 121
2 votes
0 answers
218 views

Passing RichText attributes to function onChange

I have four RichText elements in a custom Gutenberg block I am developing, and they are all very similar except for the "name" attribute, which is currently hard-coded. What I need to do is ...
Garrett Massey's user avatar
2 votes
0 answers
641 views

Nonces, AJAX, script variables & security in WordPress

Alright, so let's say you develop a website where you enqueue a js script on a page X of your frontend, using: wp_enqueue_script( 'script_handle', PATH_TO_SCRIPT, array(), '1.0.0', true ); ...
DevelJoe's user avatar
  • 487
2 votes
0 answers
232 views

Override Plugin Script Fucnction in Wordpress

I don't know how to remove a specific function from a plugin. My plugin is Photo-gallery. I want to remove this function: function spider_createpopup(url, current_view, width, height, duration, ...
Ioflvoe89's user avatar
2 votes
1 answer
2k views

Uncaught TypeError: Cannot read property 'firstChild' of null after upgrading to WordPress 5.5

I am getting the following error from comment-reply.min.js (which seems to be a WordPress file): Uncaught TypeError: Cannot read property 'firstChild' of null at comment-reply.min.js?ver=...
Ionică Bizău's user avatar
2 votes
0 answers
810 views

What is the correct way to import the blocks-editor?

I was following a blocks tutorial that was using @wordpress/editor to import some components and everything was working correctly but I was getting tons of deprecation warnings in the browser all ...
echodrome's user avatar
2 votes
1 answer
66 views

How do I store information in a dynamic block in WordPress?

I am trying to develop a dynamic block plugin where I store up to 7 links using Gutenberg and so far here is part of my code: edit: props => { const { attributes: { links = [], ...
echodrome's user avatar
2 votes
0 answers
234 views

How to handle Gutenberg wp.data async errors?

When using wp.data.select('core').getEntityRecords(...), there is a special selector for loading states wp.data.select('core/data').isResolving(...). But what about actual errors -- backend validation ...
Capi Etheriel's user avatar
2 votes
0 answers
854 views

Block editor: How to check if block editor has initialized and populated the data store?

Within some JavaScript I have to get the current post content of Gutenberg. I am accessing this from jQuery (might be bad practice, however): $(document).ready(function() { const { select }...
Blackbam's user avatar
  • 535
2 votes
0 answers
611 views

Gutenberg List Extension Block

I'm trying to extend the default Gutenberg unordered list that renders like this; <ul> <li>Item 1</li> <li>Item 2</li> </ul> To something like this when ...
Wouter's user avatar
  • 21
2 votes
0 answers
168 views

Extending wp JavaScript base class to make a post request to a custom REST endpoint

I've defined a REST endpoint /my-plugin/v1/post-read to show whether a post has been read or not, per-user. In PHP, my plugin keeps track of this depending on page views while logged in. I'm now ...
Sean's user avatar
  • 647
2 votes
1 answer
2k views

Make a list with header and subtext in Gutenberg blocks

I want to create a block in the gutenberg editor, to create lists with a header and subtext (interview format with question and answer). The list should be in an ordered list. I can't figure out how ...
Royw's user avatar
  • 121
2 votes
0 answers
141 views

How to check if customize previewer is refreshing?

I am trying to send data from customize control to customize previewer. The scripts work fine until the customize previewer is refresh. The problem is only the previewer is refresh, the customize ...
Quang.P's user avatar
  • 21

1
2 3 4 5
20