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'] =...


6

No, it creates only one file. There is no log rotation involved. But... Sometimes “but” can be a good thing ;) WP uses error_log for its debug log, so you can change its location using: ini_set( 'error_log', WP_CONTENT_DIR . '/debug-' . date('Y-m-d') . '.log' );


6

The best way would be to create a custom plugin for your site. Take a look at the plugin handbook to get started https://developer.wordpress.org/plugins/ In the plugin, you can just put the libraries in a folder, and include them in your main plugin code. Your plugin can then do one of these Register a shortcode Create a custom template tag, which would be ...


4

You can use output buffering like: $output_settings .= ''; ob_start(); settings_fields('fahad_plugin_cpt_settings'); submit_button('Delete', 'btn btn-danger btn-sm', 'submit', false); $output_settings .= ob_get_clean(); and use $output_settings variable in your code like // ...your code... $data .= '<form method="post" action="options.php">'; $data ...


3

March 2020 update: Looks like serialize_block() is included with WP since 5.3.1, though i think it's undocumented right now. Here's the source on Trac. The docstring says: /* [...] * * Returns the content of a block, including comment delimiters, serializing all * attributes from the given parsed block. * * This should be used when preparing a block to ...


3

A nice clean way of doing is using adding a custom endpoint to wordpress REST API https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/ function stripe_task() { include_once ABSPATH . 'path/to/stripe/autoloader/or/init'; //change $payload = @file_get_contents('php://input'); $event = null; try { $...


3

the async property is marked as protected, so that usually signifies that it is related more to your implementation's details rather than functionality. Ideally you would write your tests to test the public methods you have exposed. Testing that the class property you set in the constructor of one class is an instanceof what was initialized doesn't provide ...


3

It's because if the user enters large="true", then $atts['small'] isn't defined. The normal solution is to use shortcode_atts() to set default values for the parameters, but you're not putting the result of shortcode_atts() into $atts, you're just just extracting it. This means that $small will be defined, but $atts['small'] won't be. The proper way to ...


3

The main issue with your code is that the form submission will always have the same value. This could be seen by debugging $_POST where you check if $_POST['submit'] was set. I set up a custom database table and added some dummy data. I think this more or less mirrors your setup. Here is the code that creates the DB table and adds some sample data. /** * ...


3

As I said in the comment, your endpoint worked fine for me. And you said, I managed to stop giving error, but I can't get what I pass in parameters, I put the regular expression, it keeps giving the error. So not sure about that "regular expression" thing, but you can use $request->get_param() to get a specific parameter, or $request->get_params(...


3

I wonder if there is a way to hide a Wordpress Plugin's source code from users. I know wordpress is open source but i dont want the users be able to access and see my plugins source code if possible. No. In order to load the plugin it has to be runnable, and if it can be run it can be viewed. What's more, such a plugin if it were possible would be: A ...


3

Your function should look something like this function my_custom_function( $html, $content ) { $html .= get_post_field('post_content', $post_id); $html = "<div class='post'>" . $html . "</div>"; return $html; }


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

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}


2

This removes both <htmltags> and <!-- comments -->: echo wp_strip_all_tags( get_the_content() ); wp_filter_nohtml_kses() didn't get me rid of the comments. seen here


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

The accepted answer was helpful. Thanks. But prepare_item_for_response() method was deprecated since v.3.0, so, hope this snippet will help someone with a custom endpoint for WC Orders. // Parse all others params $args = wp_parse_args( $request->get_params(), $args ); // Get orders $orders = wc_get_orders( $args ); if ( ! empty( $...


2

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-...


2

Yes, it's possible. You have to create a JavaScript File and enqueue this file for admin use. This hook is to add files for the backend: add_action( 'admin_enqueue_scripts', 'your_function_name' ); This hook is to add files for the frontend: add_action( 'wp_enqueue_scripts', 'your_function_name' ); So we need to use the admin_enqueue_scripts hook and ...


2

Ok, I've managed to solve this. This is how i finally created variations custom field: add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 ); add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 ); function variation_settings_fields( $loop, $variation_data, $variation ) { ...


2

You can temporarily detach the function from the hook. // THIS IS MY PROBLEM LINE, i USE Apply Filters for post content.... $priority = has_filter('the_content', ['TableOfContents', 'writeTOC'] ); if ( $priority !== false ) remove_filter('the_content', ['TableOfContents', 'writeTOC'], $priority ); $meta = apply_filters('the_content'...


2

As @TomJNowell said, You must never nest functions like that. so First,you have to move that functions out of that shortcode function and paste separately in your plugin's file or active themes functions.php file. Second, follow what the codex says Shortcodes, If the shortcode produces a lot of HTML then ob_start can be used to capture output and convert it ...


2

As Codex says, IMPORTANT! wp_localize_script() MUST be called after the script has been registered using wp_register_script() or wp_enqueue_script(). add_action( 'init', 'my_script_enqueuer' ); function my_script_enqueuer() { wp_enqueue_script( 'jquery' ); # before enqueue,if not register then register wp_enqueue_script( 'add-order-front' ); ...


2

Your problem has nothing to do with apply_filters, it's a basic PHP mistake: public function init (){ $filter_fields = apply_filters('tbg_reg_fields', $this->fields); } Here, you create a brand new variable in the init method scope named $filter_fields, then never use it. $this->filter_fields and $...


2

You might try conditional classes instead. In your regular "style.css" file you would include both classes: .theme-header-title.green { color:green; } .theme-header-title.blue { color:blue; } (Tip 1: avoid !important, just use a more specific style if needed - for example, h1.theme-header-title.green.) Then in your HTML, which is likely in your "header....


2

This is because you're not adding elements to the array. You're overwriting them: $modified_result = array(); foreach($queryresult as $result){ $modified_result['name'] = $result->name; $modified_result['address'] = $result->address; } Your loop is setting the name and address property of the $modified_result array directly, and then ...


2

get_the_category() retrieves the current post categories. To get all categories you should use get_categories() instead


2

The do_shortcode() function is currently in the foreach loop. I don't know what are the parameters of this shortcode , but if it accepts comma separated values of term slugs: $terms = get_the_terms( $post->ID , 'shoptype' ); $i=1; $commaSeparatedvalues=""; foreach ( $terms as $term ) { $term_link = get_term_link( $term, 'shoptype' ); if( ...


2

Is this normal behaviour? Yes. On a default Apache install, only index.html is set as the DirectoryIndex (the default setting). Either in the appropriate <VirtualHost> container, or main server config you need to add a <Directory> section that specifically targets the defined document root directory. For example: DocumentRoot /var/www/html &...


2

Bitwise operators expect conditionals on either side of them to evaluate to either TRUE or FALSE. If FALSE it checks the next conditional until it finds a TRUE or all conditionals have been checked. Also, the is_page() function doesn't allow parameters to be passed in on a bitwise basis. So simply change your code to the below and you're good! <?php if ( ...


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