A type of hook that provides a way for content to be overridden programatically
19
votes
4answers
10k views
Filter to remove image dimension attributes?
I'm working on a site based on a fluid width css template which sets a max-width on images to the width of the column containing them, and I need to remove the inline width and height dimension ...
12
votes
2answers
447 views
How to remove a filter that is an anonymous object?
In my functions.php file I would like to remove the below filter, but I'm not sure how to do it since it's in a class. What should remove_filter() look like?
add_filter('comments_array',array( ...
11
votes
4answers
3k views
single-{$post_type}-{slug}.php for custom post types
My favorite part of the Wordpress template hierarchy is the ability to quickly create template files for pages by slug, without having to edit the page in Wordpress to select a template.
We can ...
11
votes
2answers
554 views
How to make a image-size selected by default in Media upload - WP v3.5
Bare with me. I want to have a custom image size selected by default in the Media upload popup page. In Wordpress v3.4.2 and prior, this elegant code worked fine:
function ...
9
votes
2answers
4k views
Explanation for apply_filters function and its variables
I'm learning how to build html forms using PHP by taking an example from "simplr form registration" plugin.
I'm looking at this code:
$form .= apply_filters('simplr-reg-instructions', __('Please ...
9
votes
3answers
4k views
Saving Taxonomy Terms
I have an interesting problem which I hope someone can quickly answer.
I have created my own metabox which, based on "MY METABOX CODE" (list below) is correctly displaying a dropdown list of all my ...
8
votes
4answers
1k views
remove_action or remove_filter with external classes?
In a situation where a plugin has encapsulated its methods within a class and then registered a filter or action against one of those methods, how do you remove the action or the filter if you no ...
7
votes
1answer
1k views
Passing a parameter to filter and action functions
Is a way to pass my own parameters to the function in add_filter or add_action.
For example take a look in the following code:
function my_content($content, $my_param)
{
do something...
using ...
6
votes
1answer
188 views
How to create an API for my plugin?
I have been developing plugins for WordPress. Most plugins I have developed with two three classes and not so huge like Buddypress, WooCommerce or etc.
I am planning to make two open source plugins ...
6
votes
1answer
332 views
Changing JPEG compression depending on image size
Short. I want ''large' images compressed by 90%, and 'medium' to be by 60%. Has many af you know, sometimes larger images suffer from high compression, but other small images don't.
This function ...
6
votes
5answers
7k views
remove empty paragraphs from the_content?
Hey guys,
I simply want to prevent the creation of empty paragraphs in my wordpress post. That happens quite often when trying to manually space content.
I don't know why this doesn't take effect?
...
6
votes
3answers
1k views
How to Pass External Variables to Filters/Actions
I find myself needing to pass custom data to a filter provided by a 3rd party plugin. All of the ways I've seen to do this are really complicated and hard to wrap my head around.
Take this example:
...
6
votes
1answer
2k views
Row actions for custom post types?
I'm working on a plugin, which converts a site into a feedback sort of portal. I made a new object page, 'Feedbacks', which displays all the feedbacks is a tabular format, and I'm using ...
6
votes
1answer
801 views
Set media upload attachment link to none and hide it in WP v3.5
In the Media upload popup page, how do I set the attachment link to none and hide it in Wordpress version 3.5? The following filter worked fine in earlier versions of WP:
function ...
5
votes
2answers
808 views
Change admin bar to default:off
While I quite like the admin bar I actually want it to be OFF by default instead of ON ( I don't want to disable it altogether because I want users to be able to turn it on if they want - but but I ...
5
votes
3answers
1k views
How to know what functions are hooked to an action/filter?
Is there a way to know what functions are hooked to a particular hook? For example if I'd like to know what functions are hooked to the wp_head hook.
Thanks in advance.
5
votes
3answers
443 views
Filter any HTTP request URI?
I want to filter any HTTP request URI done through the HTTP API.
Use cases:
The WordPress update check goes to http://api.wordpress.org/core/version-check/1.6/, but ...
5
votes
1answer
2k views
How to add defer=“defer” tag in plugin javascripts?
I couldn't add defer tag in plugin javascripts. Google developer pagespeed test suggests me to add defer tag in contact form 7 javascripts.
This is how contact form 7 includes javascript in header.
...
5
votes
3answers
3k views
apply_filters() and the_excerpt are giving unexpected results
I feel like I must be missing something pretty obvious, here, but I can't seem to get WordPress to cooperate.
I'm generating Facebook OG tags with a function. Everything works fine, except for the ...
5
votes
2answers
448 views
How to filter by post-format in admin?
I need to filter my posts by Post-Formats in admin ?
How can I do that ?
For now, Wordpress allows to filter by Categories and Dates.
5
votes
1answer
64 views
Add filter to blogroll widget
I'm trying to add <i class="icon-ok"></i> before the content inside the <li> of the blogroll widget. I'm assuming that's done through the link_title filter, but I can't find a ...
5
votes
1answer
3k views
Wordpress hooks/filters insert before content or after title
trying to insert content before the post content in my functions.php - I know how to use the regular wp hooks, but unsure how to insert into other areas.
Tried this, but it kills content on any other ...
5
votes
1answer
66 views
Add whitespace between Chinese and other letters
I want to add a space between a Chinese character and a letter or a number to make the article more readable.
For example:
Google与Apple展开的专利大战在2天之前结束。
Google 与 Apple 展开的专利大战在 2 天之前结束。
But ...
5
votes
2answers
793 views
Remove “Insert from URL” link in Media upload - WP 3.5
How do I remove the Insert from URL link in the new Wordpress 3.5 Add Media popup page? In earlier versions of Wordpress, this worked fine:
// removes URL tab in image upload for post
function ...
5
votes
4answers
1k views
No filter of code on switch from html to visual editor, how?
Yes, i have found other questions to this topic, but no have the same topic exactly and no solution for my problem.
If you include code inside the html-tab and you switch to the visual mode, then ...
4
votes
5answers
484 views
Implementing advanced add_* function wrappers
add_action() and add_filter() are major functions. However in some scenarios add one more function and hook it somewhere approach gets bulky and inconvenient.
I had determined for myself several use ...
4
votes
2answers
90 views
Valid characters for actions, hooks and filters
I haven't ever seen a tag such as do_action('something_10'). Is it invalid if I use numbers?
If the method is valid, how can I write different numbers in the tag string conditionally? For example, is ...
4
votes
1answer
2k views
Removing Image and Caption Dimension Attributes
This question is an offshoot from the this discussion on removing dimension attributes from images. The solution code provided on that thread works very well except that it has the unfortunate side ...
4
votes
1answer
169 views
Why, Where, and When to use reference pointers in filters/hooks?
Why, Where, and When to use reference pointers in filters/hooks? What are the potential cons of not using them when suggested or required? Just looking for a more detailed answer than the codex ...
4
votes
3answers
552 views
Is calling function_exists() faster or slower that apply_filters()
Is calling function_exists() faster or slower that apply_filters() ... or is the difference so small that it should not be considered?
I did a bit of testing based on Kaiser's and it showed that ...
4
votes
1answer
1k views
Adding a filter to qTranslate to change display of language chooser
This is a problem I am having with qTranslate, but I suppose the solution is more of an instruction in how Wordpress hooks and filters work.
Instead of using the qTranslate widget, I am using the ...
4
votes
1answer
2k views
How to appending to the_content using add_filter with custom post type?
I have a custom post type running fine, but some of the text in the page is the same for every post, so I want to add it in using a function.
I have this set up:
function ...
4
votes
1answer
195 views
Limit Media Library to Given Folder
I have made a plugin that uses the Media Library to allow users to upload files to a specific directory - using the upload_dir filter.
I would like to know if there is a way (i.e. a filter) I can use ...
4
votes
3answers
863 views
LESS CSS enqueue_style with add_filter to change rel attribute
What I'm trying to do is use less css with Wordpress.
You're supposed to link to your .less files with the rel attribute set to 'stylesheet/less'. But I can't figure out how to alter the code that ...
4
votes
1answer
220 views
Custom Rewrite Rules Not Sticking
I've written some custom rewrite rules for a special feature on http://www.pewhispanic.org/states/. States is a page with a custom page template, page-states.php. The logic for returning the right ...
4
votes
0answers
111 views
Custom query incorrectly returning everything [closed]
I'm missing something somewhere, but I cannot connect the dots. Everything outputs properly except that the query returns everything from the DB, not just posts. Can anyone spot a reason for this ...
4
votes
1answer
297 views
How to change “Draft” string for status of custom post type to “Unavailable”?
ANSWER MOD: just an important mod to the chosen answer:
// check if you actually have drafts; also avoids extra '|' separator
if (isset($views['draft'])) {
// 'Drafts' should be added (and come ...
4
votes
1answer
107 views
Store source permalink on XMLRPC calls
In a theme I'm developing, I need to link to the source post when the post has been stored using XMLRPC. That implies that every time Wordpress asks for a permalink (using get_permalink()) the theme ...
3
votes
5answers
2k views
Remove classes from body_class
I don't need this whole mess of classes like this...
<body class="page page-id-829 page-template page-template-page-template-portfolio-php portfolio">
I'd like something like this...
<body ...
3
votes
3answers
1k views
How to correctly get post type in a the_title filter
I want to prepend text to the post titles of a specific custom post type, but the filter below didn't work. Instead of changing only that CPT's post titles, it changed all titles on the given CPT's ...
3
votes
2answers
525 views
Custom theme hooks / filters - passing arguments
I'm getting confused trying to implement these custom theme hooks. Trying to wrap my head around that.
I thought i understood this. but now after reading code for several hours; it's made it worst.
...
3
votes
1answer
2k views
Add filter menu to admin list of posts (of custom type) to filter posts by custom field values
This answer is very close to what I am looking to do, but instead I would like to specify a specific custom field and display a select menu of its available values. Thanks!
3
votes
2answers
577 views
How to add filter with 2 args?
I want to modify $path in the following filter. It has 1 input and 2 args.
function documents_template( $template = '' ) {
$path = DOCUMENTS_INCLUDES_DIR . '/document/' . $template;
...
3
votes
1answer
580 views
get_option() filtering and getting out of recursion
get_option() provides couple of filters 'pre_option_'.$option and 'option_'.$option.
However most times I tried to make use of these it usually explodes and not worth the trouble - either I need to ...
3
votes
2answers
818 views
Earliest hook to reliably get $post/$posts
What's the earliest possible action I can hook into where I'll be able to access the global $post/$posts variables on both the front and back ends? I've tried looking through the Codex reference, Adam ...
3
votes
3answers
6k views
Filter by one custom field, order by another?
I have a custom post type "Listing" and I want to get all Listings that have a custom field gateway_value != 'Yes', and order the results by another custom field, location_level1_value. I can get the ...
3
votes
1answer
292 views
<form> inside a metabox
I'm trying to write a plugin that allows a user to upload a video to Vimeo through the Vimeo upload API.
In order to avoid trying to upload a video to a potentially shared hosting account and then ...
3
votes
1answer
160 views
Insert new element to array with add_filter
add_filter('example_filter', function(){ return array( 'tax1' ); } );
add_filter('example_filter', function(){ return array( 'tax2' ); } );
add_filter('example_filter', function(){ return array( ...
3
votes
1answer
304 views
How to apply a class to the second word in menu list item?
I want to apply a class to a word in my menu. For example, say I have a list item in my menu called "My Item". I would like to apply a class to the word "Item" so that I can style it anyway I want.
...
3
votes
1answer
67 views
How do I know if author field was changed on post save?
I'm writing a plugin that sends notifications on various post events.
One of the notifications should be sent when a post is assigned to a different author.
How can I know that the post author was ...
