2

its better to include your assets with admin_enqueue_scripts for your question add_action('admin_head', 'grup_custom_admin_post_css'); function grup_custom_admin_post_css() { $allow_post_types = array('custom_role', 'custom_role_2', 'etc'); $allow_roles = array('post_type', 'post_typ_2'); $current_user = wp_get_current_user(); if (...


1

There are several fatal assumptions here, and, a far better way to do it. 1. Declaring Functions inside Functions This will cause a fatal error in a future version of PHP, makes it super difficult to debug. But worst, it's completely unnecessary. This: function foo () { function bar () { // } bar(); } Should just be this: function bar(...


1

It's very simple: Just assign the value of shortcode_atts() (which is an array) to a variable and use it to access the shortcode attributes in the same way you access the items in any other arrays: $atts = shortcode_atts( array( 'no' => 1, ), $atts ); // Use $atts['no'] to get the value of the "no" attribute. $no = is_numeric( $atts['no'] ) ...


1

If the plugin dynamically generates script and style handles so that you can't use wp_dequeue_script and wp_dequeue_style, as you said in a comment on another answer, then you would need to fork the plugin, and remove the section of code that is doing that, or else wrap it in a conditional so that it only loads on the specific page in question. (Fork, ...


1

If you know what the names of the handles that the plugins use are, you can locate them using this code and then just use a simple wp_dequeue_script function. function wp_inspect_scripts() { global $wp_scripts; echo '<pre><h1>Script Handles</h1><ul>'; foreach( $wp_scripts->queue as $handle ) : echo '<li>' ....


1

So this is a tiny bit hacky, but it achieves want you want relatively cleanly without you needing to change your themes, which was presumably the point of wanting to do it in functions.php. First make WP_Query think it's getting all the posts with default pagination settings as usual: function change_posts_number_home_page( $query ) { if ($query->...


1

Welcome to WPSE. So I can't write all the code for you, but I would suggest you look at these main pieces, and then come back here or make new questions if you have followup questions: To alter the content of a post before it's printed to the screen you could use the the_content filter. This lets you make any changes you want at all to the content section ...


1

You assumed get_field would always return images, but what if there are no images to return? $images = get_field('fl_gallery'); $image = $images[$no]; The code never checks $images to see if it's empty, or an error value. On top of that, what if it returned images, but it returned 3 images, and $no is 4? You can't access something that doesn't exist ...


1

I've never used it, but it looks like get_main_site_id is what you want to figure that out, so therefore your code might look like: $mainSiteId = get_main_site_id(); foreach ($user_blogs AS $user_blog) { if ($userblog->site_id != $mainSiteId) { echo '<li><a href="'.$user_blog->siteurl.'">'.$user_blog->blogname.'</...


1

These images sizes are defined by WordPress, and were added in WordPress 5.3. The comments in the source code describe them like this: These sizes are meant to enhance the way WordPress displays images on the front-end on larger, high-density devices. They make it possible to generate more suitable srcset and sizes attributes when the users upload large ...


1

Is there anything special for dealing with $_POST in this case? Maybe, if you can elaborate more on what you mean by "special"? But as with other PHP arrays, you should always check if the POST variable is actually set before attempting to use it: // Example for the Edit_Email_1 input: if ( isset( $_POST['Edit_Email_1'] ) ) { return $_POST['...


1

To append strings in PHP use ., like: return $sentence['0'] . $sentence['1'] . "... Read More";


1

Instead of contacting the remote site to get the information in an expensive HTTP request, why not have the remote site send you the data at regular intervals? Register a REST API endpoint to recieve the data on In that endpoint, take in the data and save it in all.json On the remote site add a cron job grab the data make a non-blocking remote request to ...


1

These fields have the keys 'blogname' and 'blogdescription' respectively in the options table. I'm not sure exactly why you need to do this as it seems like a priority to secure your site and be able to update it through the dashboard yourself, but you can update them easily from functions.php with update_option, e.g.: update_option( 'blogname', "site ...


1

You may have already figured this one out, but here's two examples how to do this. In both of my examples I do the sorting first and rendering second. This keeps things cleaner and clearer in my opinion. Example 1 Loop queried posts and sort them into two helper arrays. If those arrays have posts, loop them through and render posts. $posts = ...


1

All I needed in my code for it to work is this: //get the repeater $car_repeater = get_field('repeater_name',$post_id); $first_row = $car_repeater[0]; //put [0] to get the first row of the repeater $first_car_model = $first_row['car_model']; //put [car_model] to get this field value in the specified row (first row) $...


1

I don't think you need to use save_post to save backend, as acf/save_post also saves when updating the post in the backend. I think (95% sure). Read the comments below in the code and see if this will help you create the custom post title you are after. Taking into account cars which only have 1 model, multiple models and no models. It's a start anyway. // ...


1

Here's how I fixed it. If you paste this code in your theme's functions.php, it will use the image set for Facebook also for Twitter if no image is set for Twitter. If there is not image set for both Facebook and Twitter, it falls back to the default Facebook image in the Yoast settings (unfortunately, you can't provide a default Twitter image there, so we'...


Only top voted, non community-wiki answers of a minimum length are eligible