Questions tagged [filters]

A type of hook that provides a way for content to be overridden programatically

790 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
9
votes
1answer
7k views

AJAX with loop filtering categories

I've been researching on how to make my loop with AJAX. I found some codes online and modified some parts but I can't seem to get it to work. This is my code for the loop: <article id="main" ...
6
votes
0answers
383 views

static variable loop not working in Wordpress

I have a function in my wordpress theme that deletes the first embedded video in a video post. See code below. This is in the functions.php file. /* - function that hides first video in post content -...
5
votes
0answers
856 views

How can I extend the Gutenberg table block transform to allow colspans/rowspans on pasted table <td> elements?

I'm trying to allow users to paste (relatively) simple tables into Gutenberg. The editor converts the raw HTML fine but strips out any attributes/classes. For the most part this is good - I want to ...
4
votes
0answers
209 views

Customize WordPress Media Manager - Media Window

Im trying to customize the wordpress media manager "add media" window to get it as simple as possible to use. So i want to disable/ hide the following fields/ functions because i dont need some or ...
4
votes
2answers
1k views

Include a page template along with add_theme_support()

I'm not even sure this is possible but before I start thinking up crazy solutions, I'll see if there is a WordPress way to do it. Here's the deal. I have a timeline jQuery plugin all set up on ...
3
votes
0answers
84 views

Remove left alignment option in core/image block

I’m trying this code to disable the left alignment option from the core/image block. I just want to make available the center and right alignment options. wp.hooks.addFilter( 'blocks....
3
votes
1answer
767 views

Why is wordpress removing some unicode characters (e.g. some emojis) when I save my post?

Try making a new post, pasting this string of emojis: "πŸ»πŸπŸ¦πŸˆπŸ”πŸ„πŸ¦€πŸ•πŸ¬πŸ˜πŸŸπŸΈπŸπŸŽπŸ’πŸΌπŸ–πŸ‘πŸŸπŸ’πŸ³" and then saving that post as a draft. When I do this (in WP version 4.7.4), it removes the emojis. ...
3
votes
1answer
44 views

How can I add a fifth option to the alignment picker?

I'd like to have the following options in the image alignment picker: Left Right Center Full None Obviously four of those are there by default, but the "full" one doesn't currently exist. The idea ...
3
votes
0answers
363 views

Prevent 404 when using pre_get_posts to filter an archive page

I have added a custom taxonomy named "area" to the default "post" post type. It's meant to organize posts by geographical area. In category pages I've added a dropdown that allows the user to filter ...
3
votes
0answers
379 views

How to display term description in empty terms archive?

I list all terms from a taxonomy, even the empty ones, but I found out that at least in 2010/2011 themes I got a 404-like message, the default seems to only display the term description when at least ...
2
votes
0answers
20 views

What's the point of the query_vars filter?

WordPress doesn't seem to support named parameters in a query string (like ?foo=123&bar=456) unless you explicitly allow them by doing add_filter('query_vars'...). Why is this? What (presumably ...
2
votes
0answers
10 views

How can I filter block registration based on post-type? (Block alignment settings)

I want to disable the .alignwide and .alignfull block alignment options (remove them from the editor UI) on the 'post' post-type only. I have tried using this block registration filter to modify the '...
2
votes
0answers
36 views

How to remove get_post_metadata using remove_filter inside a class?

This is the filter that i use. add_filter('get_post_metadata', array(WPKWP::CLASS_NAME, 'get_post_metadata'), 10, 4); I have to use the get_metadata inside the above call back function. If I use ...
2
votes
0answers
48 views

Rewriting Woocommerce Product Filters To URL Segments

I'm working with a site where product category pages are filtered using query parameters: ?color=red&brand=nike&size=10 I'd like to use URL segments instead and rewrite the request to the ...
2
votes
0answers
174 views

wp_insert_post_data filter not working correctly after upgrade to Wordpress 5

I have the following code in a project. function vb_post_modified_date_update($data, $postarr) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if (!empty($...
2
votes
1answer
377 views

Hide some items from Screen options in dashboard for products

I am trying to unset/hide some options in dashboard. I am trying it for products screen. Here is the screenshot Here is the code i tried to hide SKU /** Hide Dashboard widget by default via Screen ...
2
votes
0answers
71 views

Multilanguage URLs

I am trying to achieve multilanguage behaviour for my website. I'm very close but not quite there and feel like I'm running in circles. That's why I decide to ask for your help. I'd like to use URLs ...
2
votes
0answers
1k views

Filter custom post type archive page with custom taxonomies (categories) with AJAX

I've created a custom post type (projects) with different custom taxonomies (projects' categories). I would like to create a categories' filter but with AJAX, so without reloading the page every ...
2
votes
1answer
2k views

Modify WordPress Rest Api Request/Response

I am building an application using WordPress Rest API. I want to make simple calls to the API, such as just /wp-json/wp/v2/posts and let the backend have a systematic way how to handle this and serve ...
2
votes
1answer
131 views

where to apply “apply filters” and other Sanitization Functions

I got to learn something new today here on this post. I have code written for a Post widget β†’ <?php class chimp_post_widget extends WP_Widget { function __construct() { ...
2
votes
3answers
7k views

Filter hook before create order WooCommerce

I would like to write a little script that does a check whenever an order is created in WooCommerce (right after checkout) and then conditionally changes the Shipping Address of the customer. I think ...
2
votes
0answers
430 views

Add guid filter to attachment in media library grid mode

I'm trying to show in media modal box, attachments from a specific folder in my website and, correct me if I'm wrong, the best way to proceed is a like filter on wp_posts field GUID. Something like ...
2
votes
0answers
32 views

How to filter out post type meta?

I have used this code to filter out the post type and it works fine when showing filtered results: add_filter('wpseo_title', 'vehicle_listing_title'); function vehicle_listing_title( $title ) { ...
2
votes
1answer
788 views

Change default settings used by gallery shortcode

I need to change the default gallery shortcode settings so that "columns" = 5 & "link" = 'file'. Which filter to add to the file functions.php? Source code: $atts = shortcode_atts( array( ...
2
votes
0answers
307 views

Change file name from wp_generate_attachment_metadata

I'm pretty new and just have a hang on how wordpress data flows internal. I am confronted with applying a b/w filter on upload. no problem. I found the wp_generate_attachment_metadata filter and ...
2
votes
1answer
128 views

How to use IF Statement in WordPress?

I can't see how to correctly use the PHP if statement in my filter function below. This code works perfectly if all (3) of my $_POST inputs have values however it has a fatal error if any are empty. ...
2
votes
1answer
220 views

How to get all the predefined do_action() calls from an active theme

To hook my plugin content into anywhere, suppose I offered the theme developers to create their own hooks with a prefix (pre_) anywhere in their theme - the rest of the hook is unknown to me. So what ...
2
votes
0answers
1k views

Run oembed separately outside the_content()

I have this structure for my content.php : <div class="featured"> <!--featured image here--> </div> <h1 class="entry-title">Post Title</h1> <div class="entry-...
2
votes
0answers
2k views

How to set a custom path, for ajax image upload folder in admin?

I am coding my first Wordpress plugin that handles some data for a custom (shop-like) post type. It also has an image uploader within a metabox, where you simply drag in your images and it ...
2
votes
0answers
882 views

Pass parameter to the upload_dir filter

I'm trying to figure out a better way to pass a parameter to the function I am using with the upload_dir filter. Currently I have only gotten it to work by using sessions and/or cookie that I erase ...
2
votes
1answer
554 views

Set Item Order with wp_nav_menu_{$menu->slug}_items

I have some code that adds a menu item to a menu using wp_nav_menu_{$menu->slug}_items. It's pretty easy to add a menu item as the first or last item of the menu, but I was wondering if there's ...
2
votes
0answers
2k views

Changing image URLs in media library

On a default wordpress install, the media library is located at: /wp-admin/upload.php. I am trying to update the image URL to point to my CDN, not my local server. This filter add_filter('...
2
votes
1answer
323 views

Trying to wrap <span> around first word of multiple word strings with a widget_title() filter, only works on two word strings and not more than two

I am trying to wrap a around the first word of multiple word widget titles. I have used the answer from here: https://stackoverflow.com/questions/10263792/revised-wordpress-function-to-put-a-span-...
2
votes
1answer
405 views

Proper use of the_content filtering

This is a bit difficult without posting scads of code, but my question is: What are the benefits of filtering through apply_filters('the_content', 'anything');, and given my example loop, am I ...
2
votes
0answers
446 views

Querying posts with meta value that begins with a certain pattern

I am trying to create a search filter using meta_query. The only problem I'm having now is that I can't compare with wildcards. I think that's how you word it? $keyword = 'sos'; $tlds = array('com','...
2
votes
1answer
2k views

Refine/Filter WP_Query Posts with jQuery or Ajax

I know this has been asked many many times, but I literally searched for an answer for more than 5 hours without finding anything that drives me in the right direction. What I'm trying to achieve is ...
1
vote
0answers
16 views

Inline Styles on all native blocks

Is it possible to apply inline styles to all blocks via filters? Or do only some blocks support it? basically I want to add the ability of adding a background image to a single column. So I added an ...
1
vote
0answers
11 views

Replace youtube embed in wordpress

I am using this code to replace youtube video: add_filter('embed_oembed_html', 'foo_embed_oembed_html', 99, 4); add_filter('video_embed_html', 'foo_embed_oembed_html'); function foo_embed_oembed_html(...
1
vote
0answers
25 views

How to link the whole list item in Gutenberg's latest posts block?

I am using a Gutenberg's 'Latest Posts' block on my front page. Featured image display and grid layout are enabled in the block settings. By default, only the post title is linked to the actual post. ...
1
vote
2answers
61 views

Show only geolocated user country into Woocommerce checkout country fields

What I'm NOT trying to do: Remove or hide checkout (billing/shipping) country fields What I'm trying do to: Show only ONE country in checkout (billing/shipping) country fields, depending on ...
1
vote
0answers
11 views

Change post order random through out the entire WordPress

Is it possible to write a filter on global WP Query so that everywhere on WordPress site - all posts will be shown as random order? It will be applicable for any page like home page, blog page, ...
1
vote
1answer
23 views

How to remove SKU's from ALL products in Quick View - already remove from each product page

I have added code and removed sku's from all product pages (not admin) and all went well. However I realised that if I click on Quick View on any product - the sku's are still there. Can you please ...
1
vote
0answers
12 views

How to filter post content and force every link (<a>) made in blocks to return urldecode(<a>) with readable value?

Will really appreciate your help with something. I'm using non English letters in my URL slugs. So every time I add an internal or external link with non English letters to my post (via blocks editor ...
1
vote
0answers
28 views

How to filter, restrict and return posts based on custom user meta information

On this online platform project i have requested all users to add in their school title. In the user dashboard there is a posts section which currently shows all posts. I want to only show posts that ...
1
vote
1answer
41 views

How to check current user before all actions and filters?

I am working on a plugin with 50+ actions and filters. All actions and filters only apply to users with a specific user meta (b2b). I want to check this user meta before everything How can I do this? ...
1
vote
0answers
17 views

woocommerce_checkout_fields modifying existing billing_phone label created new field

I am adding a filter for woocommerce_checkout_fields but instead of updating the existing field label it creates a duplicate field in the woocommerce-additional-fields section as shown in the image. $...
1
vote
0answers
12 views

Filter out other users comments. Visualize only own comments and editor role users' comments

I have a similar request as per question but I am totally not into php and would not know where to start to make such edits based on the answer provided. Would be great if anyone could help here. ...
1
vote
1answer
67 views

Get Current Post ID in functions php, meta query filter

How do I get the Current post ID in functions php when creating an meta query filter? I've made many attempts but all return Null. The filter works as expected when I manually input a number, but I ...
1
vote
0answers
17 views

Remove add to cart icon/view product button woocommerce

I'm trying to remove a button that appears when hovering over the images on a woocommerce shop. (See images attached) The product is a variable product. Failing being able to do this I also tried to ...
1
vote
0answers
21 views

Separeting product from post in search result

I am trying to separete products from posts in the search result. I can see the loop there search in both. if( have_posts() ) { while( have_posts() ) { ...

1
2 3 4 5
…
16