New answers tagged functions
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 ...
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() =>...
0
votes
Remove css styles from specific page
The best solutiuon for me was to create a template with different or no head.
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, $...
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:
...
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')
...
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 ...
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 ...
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' =&...
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 $...
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 ...
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/...
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 = '...
Top 50 recent answers are included
Related Tags
functions × 5583php × 1600
plugins × 508
theme-development × 305
filters × 304
custom-post-types × 294
shortcode × 289
customization × 279
plugin-development × 273
hooks × 236
posts × 232
woocommerce-offtopic × 228
child-theme × 195
ajax × 172
categories × 170
actions × 170
jquery × 164
custom-field × 161
images × 160
wp-query × 158
menus × 152
javascript × 149
themes × 140
css × 133
loop × 125