New answers tagged

0 votes

Disable autosave with `function.php` for custom post wordpress?

There are a few methods to disable autosave/revisions. Disabling autosave: Using action and dequeuing the .js that is responsible for autosave, this goes into functions.php, located in the current ...
user avatar
0 votes

Attach a private function at a hook?

Yet another slightly more brief way is now available using anonymous functions with fn() => <?php class myAdminMenu{ public function __construct(){ add_action('admin_menu', fn() =>...
user avatar
0 votes

Remove css styles from specific page

The best solutiuon for me was to create a template with different or no head.
user avatar
  • 101
0 votes

Forcing all posts associated with a custom post type to be private

There are three hooks specifically for when the status of a post changes: /** * Fires when a post is transitioned from one status to another. */ do_action( 'transition_post_status', $new_status, $...
user avatar
0 votes
Accepted

WordPress login set cookie that survive browser exit (wp_signon function)

Without knowing what Google OAuth plugin you're using (and how it internally signs a user in), the only way is to override the pluggable function wp_set_auth_cookie, setting $remember to always true: ...
user avatar
  • 35.5k
1 vote
Accepted

How to stop media_sideload_image from running when deleting a post?

I believe you can just check if the post status is trash, and if so, don't run the rest of your code. E.g. (PS: I intentionally used strict comparison, i.e. using === as in $pagenow === 'post.php') ...
user avatar
  • 32k
1 vote
Accepted

Reset postdata not working on WP_Query in functions.php

You don't need to modify the global current post, just use the get_posts() function instead of WP_Query(). function get_root_project_value( $meta_key ) { if ( empty( $meta_key ) ){ return ...
user avatar
  • 198
0 votes

Filter nav menu items HTML tags and wrap inner text with span

Here is my solution with assistance from TheDeadMedic. I added the <svg> code to the replacement value in the preg_replace function, then added the opening and closing <span> tags to the ...
user avatar
1 vote

Filter nav menu items HTML tags and wrap inner text with span

Just use link_before in your wp_nav_menu $args and add opening/closing span tags: $args = [ 'link_before' => '<span>', /* Add closing </span> to link_after */ 'link_after' =&...
user avatar
  • 35.5k
1 vote
Accepted

I want to display latest post in marquee

You are using a local loop, so template functions won't behave as expected without a $post parameter: <marquee> <?php $latest = get_posts('numberposts=5&cat=13'); foreach( $latest as $...
user avatar
  • 35.5k
0 votes

WordPress 6.0 upgrade caused my custom function to stop working

Can't see anything deprecated, but I have spotted these: category_name expects (confusingly) the category slug, so the value should (most likely) be provider-news and not Provider News If you're ...
user avatar
  • 35.5k
0 votes

Using a function to change favorites listing

I recently needed to change the default output also. Here's how I used this filter to add the post content to the output. /** * Customize the Favorites Listing HTML */ add_filter( 'favorites/list/...
user avatar
  • 101
1 vote
Accepted

Add php code to wp_print_scripts?

You can use admin_footer or admin_head like below. This code only run on admin. You can also use for frontend by using wp_head or wp_footer function shapeSpace_print_scripts() { $block_yt_url = '...
user avatar

Top 50 recent answers are included