New answers tagged

1 vote

Wordpress Gutenberg InnerBlocks renderAppender not showing with template

I have found my typo - It should be const ALLOWED_BLOCKS = ["grid/item", "core/image"]; not const ALLOWED_BLOCKS = ["grid/item, core/image"]; If the allowed block type ...
user avatar
0 votes

Use a custom block in another block

Yes, you can create custom blocks with InnerBlocks. If you only want the parent block to include music player blocks, you can define that in ALLOWED_BLOCKS. https://developer.wordpress.org/block-...
user avatar
  • 8,683
1 vote
Accepted

How to properly package a block plugin

Create a folder named includes in the root of your plugin folder; and place your additional php files inside of there. They (andchild folders and files) should then be copied over with plugin-zip. If ...
user avatar
  • 525
0 votes

register custom post inside a custom post

yes, you can please check answers on that Link here is a simple solution add_action('admin_menu', 'vrodos_plugin_menu'); function vrodos_plugin_menu(){ add_menu_page( 'Event Page', ...
user avatar
1 vote
Accepted

How to insert and call new data in wordpress website database through a plugin

The right place to store the data depends on how you will be using the data. From the context, it sounds like metadata might be the right place. There is usermeta if the data relates to one of your ...
user avatar
  • 8,683
0 votes
Accepted

Seperate plugin and theme files

You shouldn't link directly to plugin/theme PHP files to handle requests for this exact reason - the WordPress environment won't be loaded, hence your undefined function error. Since you've ...
user avatar
  • 35.6k
0 votes

Transform internationalized plugin into internationalized mu-plugin?

Determining locale is a crucial step in loading text domain because it decides which .mo file should be loaded. If we load plugin with muplugins_loaded then current_user_id will be 0, hence .mo will ...
user avatar
0 votes
Accepted

WordPress Plugin- How to Insert Html&JS code in specific Page and specific Div

As you want to insert the button on only one/few specific pages you can simply create a shortcode[Reference] and insert it on specific page/pages. Your code will be something like: function hook_html()...
user avatar
  • 26
0 votes

wp_options not returning value for logged out users?

I suspect wp-includes/option.php is not being loaded in your environment. You must have the whole WordPress environment loaded to use get_option(). So e.g. per include_once 'wp-load.php';
user avatar
1 vote

How to add Internationalization in WordPress using Javascript/React?

I see that you do not use register_block_type in PHP, which is now recommended way to register block. I am assuming you register block in the front-end ( I am not familiar with create-block ), and ...
user avatar
  • 416
0 votes

How to allow Unfiltered HTML in a wordpress multisite install

I found this code to work for me function multisite_restore_unfiltered_html( $caps, $cap, $user_id, ...$args ) { if ( 'unfiltered_html' === $cap && (user_can( $user_id, 'editor' ) || ...
user avatar
0 votes

How to make an admin plugin menu page go full screen?

Per the comments, it doesn't seem there is anything built in for this. I included this code in my page to hide the admin menus: <style> #adminmenumain, #wpadminbar { display: none; ...
user avatar
  • 141
0 votes
Accepted

How Can i import plugin option?

Just pass the array as the second argument to update_option - WordPress will serialize the value before storing it in the database, and automatically unserialize it when you read it: update_option( '...
user avatar
  • 35.6k
1 vote

flush_rewrite_rules() not working with update_option_{$option}

flush_rewrite_rules() should be called very early within the Wordpress initialization. The reason is that the entpoints cannot be changed afterwards. A solution could look like this: function ...
user avatar
4 votes
Accepted

Custom plugin settings link doesn't append current class to menu item when visited? Why?

I noticed your apwb_settings_page() function is adding the "Postal Pricing Settings" submenu using add_options_page(), and the documentation stated that: (bold formatting added by me) This ...
user avatar
  • 32.1k
1 vote
Accepted

How do I create a custom role capability?

Tested with WordPress 6.0, and it works: add_action( 'activated_plugin',function( $plugin,$network_activation ){ add_role( 'your_custom_role_slug', __( 'Your custom role title','your-plugin-domain'...
user avatar
  • 61
0 votes

template_include filter does not render the custom template

Since template_include fires very early even before add_shorcode. This is my solution to the problem. class Api{ public static $logger = null; function Api() { add_filter('template_include', ...
user avatar
1 vote
Accepted

Create page (not the post type) dynamically

You need to register a 'rewrite endpoint' using add_rewrite_endpoint(): <?php add_action( 'init', function() { add_rewrite_endpoint( 'play', EP_PERMALINK ); } ); Now, after ...
user avatar
1 vote
Accepted

Change product_base programmatically

Use your plugin activation hook to make the change. That will only run once, when your plugin is first activated, allowing the user to overwrite that change later (if they want to). ...
user avatar
  • 35.6k
1 vote

Is there a plugin for automatically adding a word or symbol after a trigger word? I.e. Like a search and replace but more like search and add?

This would run a find-and-replace on displaying the title and content field: function wpse_406537_search_replace( $content ) { $company_name = 'The Company'; $company_name_regex = preg_quote( ...
user avatar
  • 35.6k
0 votes

Get a custom table to an array

you can take every rows from a table YOUR_TABALE_NAME "SELECT * FROM {$wpdb->prefix}YOUR_TABALE_NAME" then with the get_results() return it into an array $array finally you have somthing ...
user avatar
1 vote

Passing nonce at admin menu link

WordPress do not accept nonce in the slug that you are trying to provide in the above code. I mean in this line: 'my_dashboard&nonce-field=' . wp_create_nonce('my_action'), 'show_dashboard' I ...
user avatar
0 votes

wp_remote_get keeps timing out

just set a timeout argument for that. wp_remote_get('Your Rest API URL', ['timeout' => 20]); or you can also set it in the functions.php file: function custom_timeout_extend( $time ) { return ...
user avatar
0 votes
Accepted

How to use wp_send_json() and output the value with ajax?

You can follow below steps: HTMl Code: <button id="clickMe" data-nonce="<?php echo esc_attr( wp_create_nonce( 'my-nonce' ) ); ?>">Click Me</button> PHP Code: ...
user avatar
0 votes
Accepted

Visual composer custom element error

I had to add the element by extending WPBakeryShortCode class.
user avatar
0 votes

Automated Cart Update With Alert Box Each Time

// Display sku in cart add_filter( 'woocommerce_get_item_data', 'func_js_display_custom_item_data_in_cart', 100, 2 ); function func_js_display_custom_item_data_in_cart( $cart_item_data, $cart_item ) { ...
user avatar

Top 50 recent answers are included