Hot answers tagged

7

Disabling the sitemap is easy, just add this line to your functions.php: add_filter( 'wp_sitemaps_enabled', '__return_false' ); Removing specific posts goes like this: add_filter( 'wp_sitemaps_posts_query_args', function( $args, $post_type ) { if ( 'post' !== $post_type ) { return $args; } $args['post__not_in'] =...


7

For this example lets say we have the following do_action('bt_custom_action', get_the_ID(), get_the_title(), get_the_content()); The arguments that will be passed to add_action would be in this order the post id the post title the post content By default if we hook into our do_action without any arguments, like this add_action('bt_custom_action', '...


5

For those who might not use plugins or prefer light-weighted method. This might be of help. This method redirect attachment to the exact file instead of the attachment page and it is the method that some plugins are using. To test, by putting the following code in functions.php of the theme. add_action( 'template_redirect', 'test_attachment_redirect', 10 ); ...


5

Everything Butterend_Toast says is correct, but I want to touch on why it works that way. Under the hood, do_action() and apply_filters() are just calling the core PHP function call_user_func_array(). When you run add_action() you are storing a reference to a callable, with a number representing how many arguments that function accepts. add_action( '...


4

I had this problem with a multisite setup. On my secondary site load-scripts.php returned a 404 error. the following line in wp-config.php fixed it for me: define( 'CONCATENATE_SCRIPTS', false ); # worked for me my .htaccess file: # BEGIN manual WordPress Multisite # The directives (lines) between `BEGIN WordPress` and `END WordPress` are # dynamically ...


4

I ran into that issue too, and it turns out that it was because there actually was an error that wasn't displaying. Once I fixed that underlying error, the top margin problem went away. This is in wp-admin/admin-header.php: // Print a CSS class to make PHP errors visible. if ( error_get_last() && WP_DEBUG && WP_DEBUG_DISPLAY && ...


3

There is a function url_to_postid since WordPress v1.0.0 :) This task is easiest to achieve by using this function. url_to_postid When page is top-level page, only slug has to be given. e.g. url_to_postid('slug'); When the page is in lower hierarchy level (i.e. it has parent) you have to prepend parent slug divided by slash like so: url_to_postid('parent-...


3

You can easily check what this PHP code is doing by replacing the eval with an echo and running it. It's safer to run this not on your production website, I've run it here on repl.it: https://repl.it/repls/IrresponsibleBelovedKernel which results in the below being printed: @ini_set('error_log', NULL); @ini_set('log_errors', 0); @ini_set('max_execution_time',...


3

It seems you need to use $errors = new \WP_Error(); in your code, since WP_Error isn't part of your namespace. I ran a quick test on my machine, using wp-cli commands: Using new WP_Error(): % wp eval 'namespace PJ\NS\Test; $x = new WP_Error(); var_dump( $x );' Fatal error: Uncaught Error: Class 'PJ\NS\Test\WP_Error' not found in phar:///usr/local/bin/wp/...


3

Ensure WP_CONTENT_DIR is defined in your wp-config.php file. It will be the path to your wp-content directory. define('WP_CONTENT_DIR', '/path/to/wordpress/wp-content');


3

Here's what worked for me: My Hostgator WordPress site was throwing the same error until I commented out the top-level .htaccess file. Like so: My website is a subdomain, so it had it's own .htaccess, so that's where the php version was specified (cpanel did this automatically). I didn't have to edit wp-config.php or anything else. In the comments of this ...


3

EDIT: Original answer was inaccurate as you can do this with wp_update_post and the meta_input field As per the updated question and comments this is possible with wp_update_post (or wp_insert_post for a new record) using the meta_input key on the array, e.g.: $metaValues = array( 'key1' => 'value1', 'key2' => 'value2', // ... as many ...


3

Its not safe and not recommended. Thats action that read all Javascripts, CSS from other plugins or theme. Hide your footer with css or theme option. #footer,footer{display:none!important}


3

Ok - so, firstly you should know that it is a variable and not a function - in php this is indicated by the dollar symbol before the name: $variable as opposed to function() Second, you should note that $hook is passed as a parameter to the function block - like so: function_name( $hook ){ // this makes the variable $hook available inside the function - ...


3

Can they theoretically develop a WP plugin to access the files (or even WP config, including DB credentials) of another WP installation? Yes. If your folders are owned by the same user, run as the same user in Apache/Nginx or have read/write access to each other, then it's possible. Your installations are sandboxed at the server/host level, not the WP level....


3

The conditional first checks against what gets returned from the template_include hook. In most cases, a template will be found, and there will be no issue. We'll only move onto the 2nd conditional if template_include cannot find or cannot load the template. We then look at the WP_Theme object, which does some base-line checks to see if something is wrong ...


3

Yes it is unsafe, though not for the reasons you think. DO NOT DO THIS. If your developers can upload a PHP file to your site that gets executed, then that PHP file can undo all other security measures that you put in place. The location of the file is irrelevant. Functionally, there is no difference from editing plugins directly. Additionally, a common ...


3

Now I have familiarized myself with the above principles via the documentation and I think I have understood them now I don't know which documentation you read, but you should check the Plugin Security section in the plugin developer's handbook. And there are three main issues I noticed in your code: Before attempting to use a $_GET or $_POST variable, you ...


3

I agreed with @PatJ — you should check if get_queried_object() returns an object or not. But you could simplify your code by simply using is_category() and in_category() which are conditional tags in WordPress: if ( is_category( 3 ) || in_category( 'arta' ) ) { wp_enqueue_style( 'twentytwenty-style-2', get_stylesheet_directory_uri() . '/style-arta.css', ...


3

There is indeed an unwanted ; (semicolon) in your function (try to look at line 99 in the twentytwentyone-child/functions.php file) which likely is the cause to the syntax error. So just remove that ; and the error would be gone: function my_service_template_footer_data() { echo "<script type='application/ld+json'> { '@context': 'https://...


2

The get_the_author can directly be used to display the name of the author. There are few settings to be done on the admin for this: Under the user settings add make sure you have the first and last name fields filled up. After that see for the Display name publicly as options and select whichever format you want the name to be shown. Click save and refresh ...


2

Combined Example ( Tested in 5.2 ) Step 1: Frontend Form <form id="form-password-reset" action="<?php echo wp_lostpassword_url(); ?>" method="post"> <?php wp_nonce_field( 'ajax-resetpassword-nonce', 'security' ); ?> <div class="text-align-center margin-bottom-32"> <h3 class="...


2

I have been thinking about using Wordpress' meta keys as session variables. Something like this: add_user_meta( int $user_id, string $meta_key, mixed $meta_value, bool $unique = false ); Wordpress will keep the meta values, link them to a user, and you can delete those values later on.


2

In my case, this code worked fine: $current_url = home_url($_SERVER['REQUEST_URI']) I hope it will help someone, I tried all answers but this one was helpful.


2

<?php $downloads = $product->get_files(); foreach( $downloads as $key => $download ) { echo '<p class="download-link"><a href="' . esc_url( $download['file'] ) . '">' . $download['name'] . '</a></p>'; } ?> Check this.. Worked for me.


2

If you are using docker-compose and the WORDPRESS_EXTRA_CONFIG as I was, when I stumbled across that error, the solution would be to use double-dollar-sign notation as described in a corresponding issue in the docker-compose repo on GitHub. This additional environment variable is described in the "How to use this image" of the official image ...


2

You can submit meta_input as an - (array) Array of post meta values keyed by their post meta key <?php $my_post = array( 'post_title' => $_SESSION['booking-form-title'], 'post_date' => $_SESSION['cal_startdate'], 'post_content' => 'This is my post.', 'post_status' => 'publish', 'post_type' => 'booking', '...


2

The problem is that when the special subscriber tries to Add New a sub-cpt post, it is denied permission. However, when the CPT menu is a top-admin-menu, then everything works out fine. The issue is related to the placement of the CPT's UI menu in the back-end: if it's top-level (show_in_menu=TRUE), all is well; if its a submenu (show_in_menu='my-menu-...


2

"Practice" is a matter of personal preference. The opening and closing PHP tags (<?php and ?>) are there as a matter of convenience. Basically, try to write your code in context. In example, // PHP code here ?><a href="<?php the_permalink() ?>"><?php the_title() ?></a><?php // PHP code here looks (to me) like HTML code plopped right ...


2

The solution that was provided here did not work for me. It seems that the order items are assigned to the order after the woocommerce_new_order hook is triggered. I only managed to sort my issues after I changed the hook to woocommerce_checkout_order_processed as per below: add_action( 'woocommerce_checkout_order_processed', 'get_order_items_on_checkout', ...


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