Tag Info

New answers tagged

0

For those of you who may be wondering what this does - I have figured it out. When a new function is added to an action/filter hook, it is added at the end of the array. However, WordPress specifies that those functions are to be executed by priority. When a function is added, merged_filters is used to keep track of whether functions for a hook have been ...


1

The first problem you didn’t even mention is: you are putting shortcodes into a theme. Shortcodes are pure plugin territory, because they are changing post content and must survive a theme switch. Once you fixed that and moved the shortcodes to a plugin named inferno_shortcodes, the rest is easy: In your plugin ask for theme support: $default_templates = ...


0

I develop and utilize shortcodes too, and I found passing options as attributes works well. For example, your shortcodes can accept extra parameters such as: [recent_posts thumb="true" date="false"] Then in your shortcodes, you just need to write conditionals to check for the attributes. The official documentation describes how to retrieve the attributes ...


0

The variable $theTitle is not interpolated in a single quote string. query_posts('category_name=.$theTitle&orderby=rand'); Will ask for exactly that string. $theTitle will not be replaced with a title and the dot (.) will remain in the query. The result will be unpredictable. So, use a double quoted string: query_posts( ...


1

You could attempt to alter the allowed protocols. function wp_allowed_protocols_unc_wpse_100080($protocols) { return $protocols + array('file'); } add_filter('kses_allowed_protocols','wp_allowed_protocols_unc_wpse_100080'); And add links of the form file://///path/to/file.txt-- see ...


0

If you want to filter the post on the basis of taxonomy then you use 'tax_query' to 'wp_query' eg: $args = array('post_type' => array('custom_post_type_1','custom_post_type_2') 'numberposts' => -1, 'posts_per_page'=> 10, 'paged' => $paged, 'tax_query'=>array('relation'=> 'OR/AND' ...


0

I wrote a plugin for that. It is not in the plugins repository yet, you can download it here: http://basics09.de/download/b09.link-to-existing-content.zip Install it and then put this filter in your functions.php: add_filter("link_to_existing_content_post_types", "my_link_to_existing_content_post_types"); function ...


0

a non js solution without hacking the core. try this in your themes function.php add_filter( 'wp_get_attachment_image_attributes', 'remove_image_text');function remove_image_text( $attr ) { unset($attr['alt']); unset($attr['title']); return $attr;}


0

Got the idea from this post to change my query : How to "orderby" the first array in a meta_query that uses multiply keys? I moved the state query into the larger array of queries, freeing the 'meta_key' value to be assigned to event date $args = array( 'post_type' => 'tf_events', 'meta_query' => array( $relation, ...


0

You can use my custom function to filte the content (it's from NARGA Framework) If the post has custom excerpt, display it instead the content Auto generate excerpt from the conten if the post hasn't custom cerpt Auto trim shortcode, HTML code, remove [...], add "Read More" text (translatable) /** * Auto generate excerpt from content if the post ...


0

Based on this awesome tip by @Rarst: You can use get_post_field() function to get a raw copy of it from the post object. Here's a (possible) solution I've just now slapped together: /** * Head/deck handling. * * Unaltered example title (no quotes): "First half | Second half" * * @see http://stackoverflow.com/a/16279114/922323 * @see ...


2

Without doing Ajax (like in Quick Edit), the admin_url should be the very edit.php page. Note that: the filter post_row_actions takes two arguments, the second one being $post, so the global is not necessary. instead of using id as query argument, it's best practice to use custom names, in this case update_id. I didn't know the function get_admin_url ...


0

OK, duh: I needed to have my plugin in the /mu-plugins dir to make its filter available early enough for function wp_get_active_and_valid_plugins().


4

I am not sure I understand your issue right, but my guess is your conundrum - how to get to the title that is unchanged by your filter, if you are filtering it everywhere? You can use get_post_field() function to get a raw copy of it from the post object. However instead of messing with output (and making your saved data dependent on filters being present) ...


4

You can use the global $wp_filter array to check for callbacks on each filter. Here is for example a code snippet that prints out all the callbacks on the the_content filter in the footer part of your theme: add_action('wp_footer',function(){ global $wp_filter; printf('<pre>%s</pre>',print_r( $wp_filter['the_content'],true)); }); ...


0

Oudin, I will answer here the CSS part of your question: Use this to remove the list bullets: .ul.product-categories, ul.children{ list-style-type: none; } Use this to make only the main categories bold: li {font-weight:normal} // you need to set the default state first of the list ul.product-categories > li{font-weight:bold;} //then you can ...


2

I am not going to write your form for you, but create a form and submit it to a page to do the processing, or use the AJAX API. Then use WP_User_Query to actually search for users. It is a very WP_Query-like class that should let you do everything you want including search for user metadata from the $wpdb->usermeta table by passing a meta_query parameter ...


11

The API you offer in a plugin or a theme depends on the logic of that specific code. There is probably no guide that applies to all situations. I am a contributor for multiple plugins with APIs, and what I have learned so far is: Do not offer an API until you really know how people use your code. Release the first two or three versions without any API. ...


0

I disabled the parent boxes to avoid shifting parents to the left. add_action( 'admin_footer-post.php', 'wpse_98274_disable_top_categories_checkboxes' ); add_action( 'admin_footer-post-new.php', 'wpse_98274_disable_top_categories_checkboxes' ); /** * Disable parent checkboxes in Post Editor. */ function wpse_98274_disable_top_categories_checkboxes() ...


0

This should be backward compatible and error free "{$prefix}plugin_action_links_{$plugin_file}"


3

When user starts typing something into tag input, JavaScript makes request to admin-ajax.php with action set to ajax-tag-search to receive list of suggestions (if any). In that file that action is recognized as belonging to core and wp_ajax_tag_search() function is added to dynamically generated wp_ajax_ajax-tag-search hook, which fires almost immediately ...


0

Use a Year-Month-Day notation for dates that allows numerical sorting. YYYMMDD is the most common choice. Example May 7, 2013 would be entered as 20130507. May 3, 2013 would be entered as 20130503. March 12, 2013 would be entered as 20130314. A numerical sort of those dates would yield either 20130314, 20130503 and 20130507 or the reverse depending on ...


2

To clean up a complete array use the helper function __return_empty_array() as callback: add_filter( 'woocommerce_screen_ids', '__return_empty_array', ); Similar helpers for further usage are: __return_true() __return_false() __return_zero() __return_null()


1

str_replace will make a mess of any unlucky markup on the page since it will replace matching text inside of markup or inside of URLs. What you want is a modified versions of an answer I gave to another question about highlighting search terms. The change would be to the highlight_search_term function. You just need to alter it to use the $_GET data ...


0

change rel=stylesheet to rel=stylesheet/less in $tag definition.. also rel=alternate stylesheet/less, doesn't work..


1

Check the Filter Reference -- there are filters like the_content, the_title, wp_title, etc. I'm not sure what you'd filter to get the logo description and footer -- you might need to delve into your theme's code. Also, make sure you sanitize anything you get from $_GET -- never ever trust user-generated content. See Data Validation for more information.


1

Since you're generating things on the fly, we can use a global flag to let us know when we want the title applied. add_filter('the_content', function($content){ if(is_page('compare')){ global $asin_doing_template; // mark that we're doing a template $asin_doing_template = true; $asin = esc_attr($_GET['asin']); $data = get_data($asin); ...


1

Yes, of course: function my_mail() { add_filter('wp_mail_content_type','set_content_type'); wp_mail(); remove_filter( 'wp_mail_content_type', 'set_html_content_type' ); }


0

I came across this thread trying to solve the same problem - this is what I've come up with. I don't know how well this performs, since it'll be called for every single menu item, but it seems menus are set up as taxonomies inside WordPress, and so you can use has_term() to determine if the item is in a particular menu, and get_nav_menu_locations() to pull ...


2

This was done to restrict the effect of those filters to this one query between both calls. There are probably other instances of WP_Query during page load, and you don’t want to change their results. Imagine what happens when you do not remove the filter: All later new WP_Query(); calls would be restricted to a certain date period. All posts from an ...


3

What are Filters? Filters are functions that WordPress passes data through, at certain points in execution, just before taking some action with the data (such as adding it to the database or sending it to the browser screen). Filters sit between the database and the browser (when WordPress is generating pages), and between the browser and the database ...


4

Try to see the function with better names: apply_filters( $filter_name, // used for add_filter( $filter_name, 'callback' ); $value_to_change, // the only variable whose value you can change $context_1, // context $context_2 // more context ); So when that function is called as: // wp-login.php line 94 apply_filters( ...


3

You should never ever modify WordPress Core files. WordPress has an Plugin API (http://codex.wordpress.org/Plugin_API) that allows you to modify WordPress to your liking without changing Core code. In your case, the solution is to check the contents of the custom meta box fields before they are saved via the save_post action. If the content is not valid, ...



Top 50 recent answers are included