Tag Info

Hot answers tagged

7

If you need this to be a PHP solution. You could do something like this using 'the_content' filter. This will add the class name "content-img-wrap" to any paragraph that wraps only an image tag when Wordpress prints your post content. So this will not wrap a paragraph with an image and a span. See update if that is what your looking for. add_filter( ...


4

Just look at the source of get_post_type_archive_link(): return apply_filters( 'post_type_archive_link', $link, $post_type ); Sidenote: The function uses home_url(), which is a wrapper for get_home_url(), which offers another filter: return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id ); that runs earlier. With "pretty permalinks" ...


4

Welcome to WPSE Ittikorn! Sometimes it is the easiest to just look right at the source. There even is a link right at the bottom of the Codex page you linked: https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/link-template.php#L1112 There you can easily see that there actually is a filter called post_type_archive_link So to give you an ...


3

The filter is post_type_archive_link, defined (WP 4.1.1) on line 1112 of file wp-includes/link-template.php: apply_filters( 'post_type_archive_link', $link, $post_type ); And the use: add_filter( 'post_type_archive_link', function( $link, $post_type ) { //Do something return $link; }, 10, 2 );


2

the_title() calls your function again. If you want to avoid that, remove the callback inside of your function: function filter_title_after() { remove_filter( current_filter(), __FUNCTION__ ); // the rest of your code. But you shouldn’t call the_title() in your function at all: it prints the title – this is not what you want – and you get the ...


2

publish_post doesn't work for custom post types, the correct hook (action hook) is publish_{$custom_post_type}. You should use add_action() as this is an action hook. I also tend to make use of the transition_post_status hook which is a much more universal hook as it fires everytime a post's status is changed regardless. You can use $old_status and ...


2

I found the key: SQL CASE Expression add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 2 ); function order_search_by_posttype( $orderby ){ global $wpdb; if( ! is_admin() && is_search() ) : $orderby = "CASE WHEN {$wpdb->prefix}posts.post_type = 'artist' THEN '1' WHEN {$wpdb->prefix}posts.post_type = ...


2

WordPress creates automatically filters for each theme_mod with this format theme_mod_{name}. The filters are called in get_theme_mod(). In your case, nav_menu_locations is the theme_mod and this filter is created by WordPress: //$value of the mod is passed to filter callbacks apply_filters('theme_mod_nav_menu_locations', $value); For reference: ...


2

Some of the filters and actions are hybrids of a constant part and a variable part, something like (not a real hook) {$post_type}_save_post can be used in the code and trigger the action/filter for post_save_post and page_save_post depending on your code flow. Therefore it is not always obvious how to find the place which triggers the action in the code, and ...


1

Thanks for the response David. I found the solution. I added the following code in functions.php add_filter('get_the_excerpt', 'process_excerpt'); function process_excerpt($param) { global $post; if(in_category('MY-CATEGORY-SLUG',$post)) return 'adding some data'.$param; else return $param; } This fixed my issue.


1

I think what you need is the set of filters and actions to add custom columns to post edit screens: manage_edit-post_type_columns: used to add columns manage_posts_custom_column: used to print the content of each row of the column manage_edit-post_type_sortable_columns: used to register sortable columns. Undocumented. request: you may need to use this ...


1

I figured it out: $the_query = new WP_Query(array( "numberposts" => -1, "post_type" => "plays_events", "meta_query" => array( array( "key" => "show_times_%_date", "value" => $this_month . "[0-9]{2}", "compare" => "REGEXP" ) ), ));


1

Your function does not have to accept all arguments, you can not specify the number of accepted arguments and it will default to passing just the first. You can also specify any number up to and including the total number of arguments. For example if you only need the first 2, this will also work: function my_filter_func( $redirect_to, ...


1

While I understand wanting the front end to be as lean as possible and therefore stating you want a PHP solution... JS/jQuery is probably loaded on your front end already JS/jQuery is exactly designed for this use case (you already have an answer for that, which I have not tested) PHP REGEX is not an ideal way to handle this... further reading (follow its ...


1

The Title of this post is for unregistering widgets not really sidebars, though I am glad the user got what they were looking for. For those searching for how to unregister widgets using a child-theme where the widget was registered in the parent theme, you can do that with this: Assuming the Parent Theme's Widget is registered at the widgets_init hook, all ...


1

I would go about this slightly differently. Still using the wp_get_nav_menu_items filter, but first I'll build an array containing the IDs of all empty terms. Then I'll compare each of the $items to this for potential exclusion: add_filter( 'wp_get_nav_menu_items', 'wpse177082', 10, 3 ); function wpse177082 ( $items, $menu, $args ) { global $wpdb; ...


1

The easiest solution would be to use a plugin I think: Ban Hammer provides the functionality you require.


1

See this hook: register_post add_action('register_post', 'ban_email_2334', 10, 3); function ban_email_2334( $username, $email, $errors ){ $result = array(); // check if email is from the provider you wish to ban preg_match('/bannedprovider.com/i', $email, $result); if( !empty( $result )){ $errors->add('spam_email', __( 'Some ...



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