Detect permalinks when passing querystring in REST API requests

In more recent browsers (everything but IE, essentially), there are some useful APIs for working with URLs that will make this easier: let url = new URL( MY_PLUGIN_WP_REST_API_CONFIG.baseUrl ); url.searchParams.append( ‘per_page’, 100 ); url.searchParams.append( ‘order’, ‘asc’ ); fetch( url.toString() ).then(); With those methods the per_page and order parameters will be added correctly regardless of whether … Read more

Custom form action to handle data inside a plugin

admin-post.php is perfect for that. You have to do three things: 1. Set action for your form to admin-post.php <form method=”post” action=”<?php echo admin_url(‘admin-post.php’); ?>”> 2. Add hidden input with name=action <input type=”hidden” name=”action” value=”my_plugin_action” /> 3. Register your callbacks for admin_post_{$action} and admin_post_nopriv_{$action}: add_action( ‘admin_post_my_plugin_action’, ‘my_form_processor’ ); add_action( ‘admin_post_nopriv_my_plugin_action’, ‘my_form_processor’ ); function my_form_processor() { … Read more

Dropdown menu on custom page with product to choose number of products per page

Maybe this would work? function ps_pre_get_products_query( $query ) { $per_page = filter_input(INPUT_GET, ‘perpage’, FILTER_SANITIZE_NUMBER_INT); if ( ! is_admin() && is_woocommerce() && is_page() ) { $query->set( ‘posts_per_page’, $per_page ); } } I tested your code and the if statement didn’t seem to work with is_page() (but that could also be because my local WP sandbox is … Read more

Add keywords meta to index.php page

I guess you use metadata to store keywords for other pages. One way if to use some page for the source of homepage keywords. Other is to add theme option for home page keywords: https://blog.templatetoaster.com/wordpress-settings-api-creating-theme-options/ Afterwards: add_action(‘wp_head’, ‘my_wp_head’)); function my_wp_head() { if ( is_front_page() ) { $keywords = get_option(‘homepage_keywords’); echo ‘<meta name=”keywords” value=”‘ . esc_attr($keywords) … Read more

Editing admin pages in WordPress [closed]

There are no templates for the admin pages. You have two options to manipulate them, anyway: Use filters to edit the pages (See the WordPress codex). Change the page using CSS (also using a hook or use an existing plugin like Add Admin CSS). There are more plugins that help you changing the admin backend … Read more