New answers tagged

1

Just to be sure, is "last WordPress version" the 5.8? wp_enable_block_templates is a function added in the version 5.8 of WordPress. You should find it in wp-includes/theme-templates.php as you can see here. Check if that function is actually present in your file. If not, probably something gone wrong during the updating. How did you do that? ...


0

get_current_screen is an Admin API, it can't be used on the frontend, only in /wp-admin screens. If you want to run javascript code only on certain pages, either enqueue it on those pages, or load it on all pages and check the body classes, or many other methods. get_current_screen is not the way to do it.


1

save_post becomes unwieldy under Gutenberg, in my experience. It fires at least twice, and none of the checks you have in place will distinguish between instances. I would consider replacing it with wp_after_insert_post, which was introduced into core for this very reason.


1

When you add a filter to post_type_link, you are telling WordPress to run the hooked function on the result of the get_post_permalink() function. So any time that function runs, so does yours. When I tested the filter myself, I only saw a printed message once for each link, but if you have something like this: if ( get_permalink() ) { the_permalink(); } ...


0

You should use function has_action. Function has_action( string $hook_name, callable|false $callback = false ) This function checks if any action has been registered for a hook. Parameters $hook_name (string) (Required) The name of the action hook. $callback (callable|false) (Optional) The callback to check for. Default value: false More information Please ...


0

You can use the register_post_type_args filter and just set the show_in_nav_menus argument to false. E.g. add_filter( 'register_post_type_args', 'my_register_post_type_args', 10, 2 ); function my_register_post_type_args( $args, $post_type ) { if ( 'post' === $post_type ) { // or use below to check against two or more post types // if ( in_array( $...


1

Remove the function inside the function, and instead call the wp_register_script and register_block_type inside the large function. Finally, remove the inner add_action() call, so you only have the ending one for the large function. function irm_lockdown_author_role() { if (isset($userrole->roles[0])) { $current_role = $userrole->roles[0]; } else {...


2

The error happens because the filter callback (shapeSpace_disable_sitemap_post_meta()) expects to receive two parameters ($args and $post_type) and yet you call add_filter() without setting the fourth parameter to 2. So to solve the problem: // Replace this: add_filter('wp_sitemaps_posts_query_args', 'shapeSpace_disable_sitemap_post_meta'); // with this one:...


1

Sitemap Provider It's possible to create a so called custom sitemap provider and register it with wp_register_sitemap_provider(). It's helpful to look at the core setup, e.g. for the WP_Sitemaps_Posts provider and also the dev notes. Basic Example - Sitemap with custom URLs Here's a very basic example that adds the wpse provider that extends ...


1

Do no modify the queried_object property, instead use the set methods to modify the query to achieve your desired output. Below example will work. Use only one of the query, page_id(when you are setting a page id) or post__in/p (when you are setting post_id's array or a post_id respectively). function replaceQuery( $query ) { if ( !is_admin() &&...


2

It's called post state, but not to be confused with post status (publish, draft, etc.) (although the state can of course contain the post status), and the core WordPress function which adds the post states such as the Privacy Policy Page to the posts (Posts, Pages, CPTs) list table is _post_states(), but the states are retrieved using get_post_states() which ...


Top 50 recent answers are included