Questions tagged [filters]

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

666 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8
votes
0answers
6k 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" ...
5
votes
0answers
326 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 -...
4
votes
0answers
320 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
375 views

Gutenberg: Is there a way to know if current block is inside InnerBlocks?

So I am using nested blocks in Wordpress Gutenberg. I am applying a wrapper on my elements that apply a bootstrap container class. Obviously I'd only want that on the outermost blocks, not on the ones ...
4
votes
0answers
920 views

WooCommerce How to pass/get data to/from the data-product_variations object?

Wondering if I could get some pointers on how to pass/get data to/from the data-product_variations attr form in Product Single pages. I am working on some interactions with the product gallery images ...
4
votes
0answers
201 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 ...
3
votes
1answer
442 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
43 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
292 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
359 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 ...
3
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 ...
2
votes
0answers
117 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
184 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
58 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
887 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
80 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
0answers
356 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
381 views

Filter on the_content ignores shortcodes

My function only affects the Page content and not the page content from the posts in page plugin which I call with a shortcode in the page. My plugin function add_filter('the_content', '...
2
votes
1answer
627 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
1answer
101 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
132 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
987 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
2answers
1k views

Using add_filter() in Widgets

Just have a query reference the add_filter() function. Can you use this function inside a WordPress widget class. Example I have a widget with dynamic created code that I want to pass to another ...
2
votes
0answers
820 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
473 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
292 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
311 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
443 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
1k 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
2answers
40 views

Remove “Private” + “:” in title does not work

I would like to remove the "private" prefix for each post title. I found the filter here. I managed to removed the word "Private" but when I concatenate with " : ". That does not work anymore. I ...
1
vote
0answers
17 views

Set default terms for new posts / CPTs

I want to set default taxonomy hierarchical terms for NEW posts or CPTs. That is, I want the term's checkbox to default to checked - visually - in the post-new.php editor before it's saved or assigned ...
1
vote
0answers
31 views

Add filter by custom field to block of posts

I need to put a block on a page that displays 'highlighted posts' manually. First of all, I do not know if there is a better way to do this, creating a new block, or using an existing plugin ... (...
1
vote
1answer
75 views

Can paginate_links() be customized for a specific category or tag?

I am creating category and tag page templates for my client so they can post news articles to the news category page and specific news pages separated by tag with a pagination nav at the bottom of ...
1
vote
0answers
43 views

Admin Backend - Search Pages only by title

I want to modify the pages search in the Admin Backend, so that the search only factor the title of the pages and not the whole text/article. I already found a code for functions.php that works ...
1
vote
0answers
22 views

Add filter when image is uploaded?

I'm trying to use this code from another SO resopnse: function ajx_sharpen_resized_files( $resized_file ) { $image = wp_load_image( $resized_file ); if ( !is_resource( $image ) ) ...
1
vote
1answer
186 views

Change WordPress image URLs via filter

I'm planning to create a wordpress plugin that will offload uploaded images to external website and show them from there. What I did so far: 1) Whenever a images gets uploaded, my custom functions ...
1
vote
1answer
57 views

Remove the first 5 characters of the_title and orderby that

I have a custom post type where all titles are dates (in this format: YYYY-MM-DD). I need to order them by month then day, but not at all by year. So I imagine I need a filter to 'look' 5 characters ...
1
vote
0answers
19 views

How to add custom classes to figure element only if image has caption?

I want to add the 'wp-caption' class to the figure element only if the image has caption. How do I do that? I'm using the new gutenberg enviroment, if that affects anything. for example: form this: ...
1
vote
1answer
47 views

Remove a div from RSS feed

If someone can help to remove a div from my RSS feed. I want to remove below code from my RSS feed. <div class="well"> <a class="btn" href="foo.com">foo</a></div> Thanks in ...
1
vote
0answers
27 views

How to prepare WordPress Rest data for Preview Changes?

I am currently building a custom theme by using WordPress Rest API, ACF and Vuejs. I am able to delete some data for published pages/posts using rest_prepare_page filter and rest_prepare_post filter....
1
vote
0answers
111 views

Custom preview_post_link not working for draft post

I am trying to change the functionality of the preview button so the URL can be changed to the address I want. I am using the code below function preview_link_fix( $preview_link ){ $mydomain = '...
1
vote
0answers
191 views

Filter posts in category archive page by year using a dropdown

I'm trying to filter my posts by year in different categories by changing the query using a dropdown with this code: <form method="post" action=""> <...
1
vote
0answers
23 views

What is the downside of using a filter as a “poor man's” dependency injection?

First of all, I don't know whether or not "dependency injection" is the right term to use, what would be "dependencies" in my case are really objects that I use within other "parent". I have a big ...
1
vote
0answers
15 views

How to add an extra variable to login and authenticate it?

I want to add an extra variable to my custom login and to authenticate it to then add it to an SQL database. My custom login: <?php require('wp-load.php'); require('site_config.php'); function ...
1
vote
1answer
41 views

How to validate recaptcha on comments form?

I've added the following code to my function file to add the recaptcha, however I do not know how I can validate the captcha. /** * Add Captcha to Comments Form */ add_filter('comment_form', ...
1
vote
0answers
29 views

How to properly modify WP Vary or any existing headers?

I have a site that currently have a some part of the headers like: Vary: Accept-Encoding, Cookie I want to modify it to be: Vary: Accept-Language I tried the suggestions here using this code ...