New answers tagged

0

This is the solution I arrived at with thanks to the pointer from @bravokeyl So, to be clear it does not add the ID's to links but by using the link slug I'm able to get the ID which is a solution for what I need. I'm using JS to pass the URL into this function and then stripping it down to the slug only which is used within get_page_by_path which then ...


0

I solve the problem by hooking my function to delete_attachment hook, then putting the debug trace inside my function and filtering the wp_delete_attachment, by this I can retrieve what file and line number where the wp_delete_attachment is called. add_action( 'delete_attachment', 'your_function' ); function your_function($postid) { $trace = ...


0

add_filter ( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 ) Hook a function or method to a specific filter action. WordPress offers filter hooks to allow plugins to modify various types of internal data at runtime. A plugin can modify data by binding a callback to a filter hook. When the filter is later applied, each ...


0

You need to hook your function to delete_attachement hook, but you also need to remove some extra functions that are called before calling your hooked action to reach the right caller of wp_delete_attachment(). Here's a possible implementation... function my_backtrace( $post_id ) { $bt = debug_backtrace(); array_shift( $bt ); // Remove ...


1

If you check out the source of WP_Customizer, you'll see there is no title_tagline or header_image at the time the filter runs: final class WP_Customize_Manager { protected $components = array( 'widgets', 'nav_menus' ); public function __construct() { // a bunch of requires $components = apply_filters( ...


0

It depends what you want to do. If you look into the function definition, you'll notice some do_action(): For example: do_action( 'delete_attachment', $post_id ); do_action( 'delete_post', $post_id ); do_action( 'deleted_post', $post_id ); These are points, called hooks in WordPress, where you can actually run your stuff. Hooks will help you to modify ...


0

previous_post_link() and next_post_link() should work inside the the_content filter. There is nothing wrong with your code except you must return the value inside the filter instead of print. Otherwise I believe post link should be there at the beginning of content. previous_post_link() and next_post_link() print the output so consider using ...


0

So I figured it out. I added the $arg that was provided through plugin $identify and copied the rest of the information from the plugin to overwrite everything.. and finally after 2 weeks asking, searching and trying it does what i want. Here's the filter I used without altering the plugin: add_filter( 'segment_get_current_user_identify', ...


1

You should never change a core file. This message is called by the function wp_get_attachment_link(). For this singular message this function does not apply a filter, but it return the string as value, which can help. You can simple identify where in your theme this function is called and change it return, like: $result = wp_get_attachment_link(); if ...


1

There is no clean way to filter whole sidebar and such, but then that's not what you really need. The calendar widget (assuming you mean native one) uses get_calendar() function, which passes result through get_calendar filter. It would be preferable to filter its queries, but from quick look at the code they seem highly messy and not easy to override.


0

This is how I bootstrapped youtube embeds in one of my projects. /** * Responsive Youtube embeds. */ add_filter( 'embed_oembed_html', function( $html, $url, $attr, $post_ID ) { if ( false !== stripos( $html, '<iframe ' ) && false !== stripos( $html, '.youtube.com/embed' ) ) { $html = sprintf('<div class="embed-responsive ...


0

Just as Zlatev recommended, I tried to get my data earlier and hook into the Yoast SEO plugin earlier. This worked fine for me. Had to write three new functions to get the desired data from my external data source, but now I have no more problems with setting title, open graph image and more. Lesson learned: Write (wrapper) functions to have your data ...


0

You can use the cat_is_ancestor_of() function to check for child categories. http://codex.wordpress.org/Function_Reference/cat_is_ancestor_of


2

The add_attachment action is fired when the wp_insert_attachment() function is called to add an item to the media library. Images are added to posts after going into the media library first. Even when adding via the post editor, items are added to the library with wp_insert_attachment() then to the post. add_action( 'add_attachment', xyz_my_function() { ...


2

In general I wouldn't recommend modifying the original uploaded image files, just in case we might need to re-generate intermediate sizes. But let's see if it's possible :-) We can in general let WordPress choose the image editor, that depends on modules like GD or Imagick, through: $editor = wp_get_image_editor( $file ); but this can return an WP_Error ...


0

There is a plugin called Resize Image After Upload: <?php /* Plugin Name: Resize Image After Upload Plugin URI: https://wordpress.org/plugins/resize-image-after-upload/ Description: Simple plugin to automatically resize uploaded images to within specified maximum width and height. Also has option to force recompression of JPEGs. Configuration options ...


0

This answer could help you: http://wordpress.stackexchange.com/a/69287/92649 You would need to upload your image at a higher resolution than "large" to have that effect, though


2

Most obvious reason could be the fact wpseo_title filter is firing before you have saved your title. Try moving title_storage() call on a earlier stage like. The wp action should be a good candidate.


0

This is a much simpler solution - add the following to your functions.php file: add_filter('wp_nav_menu_items','add_search_box_to_menu', 10, 2); function add_search_box_to_menu( $items, $args ) { if( $args->theme_location == 'primary' ) return $items."<li class='menu-header-search'>".get_search_form(false)."</li>"; return ...


0

Adjust the single-product-reviews.php template file and add a conditional check. How to limit users to one comment per post


0

Fixed: Search and result the all keys; <?php $the_keys = preg_split('/\s+/', str_replace('-',' ',get_query_var('s')),-1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $total_keys = count($the_keys); $the_query = new WP_Query(array('post_type'=>'nothing')); if($total_keys>1){ for($i = 0; ...


0

This shows a more readable list of filters function print_filters_for( $hook = '' ) { global $wp_filter; if( empty( $hook ) || !isset( $wp_filter[$hook] ) ) return; $ret=''; foreach($wp_filter[$hook] as $priority => $realhook){ foreach($realhook as $hook_k => $hook_v){ ...


0

Maybe somebody like me want fuzzy logic results I solved this way: "search.php" <?php $the_keys = preg_split('/\s+/', get_query_var('s'),-1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $total_keys = count($the_keys); // Count the search term $the_query = new WP_Query(array('s' => get_query_var('s'))); // IF have ...


0

You are getting into deep water quickly. I would look into SearchWP plugin as they provide LIKE searching and Fuzzy matching. SearchWP


1

@AlexanderFarber, there are many way to attach attribute class under wp_nav_menu link. I agree with @Sumit, adding page links in Appearance > Menu WordPress take care of current-menu-item class or current_page_item class. Also, this way is best practice to handle your nav menu in the future. Create dynamic link in wp_nav_menu Since your question related ...


0

Here is my own solution - in the /wp-content/themes/twentythirteen-child/functions.php file add the current-menu-item CSS style if the page slug is player: function my_nav_menu_items( $items ) { $profile = sprintf('<li class="menu-item menu-item-type-custom menu-item-object-custom %s"><a ...


0

Can't seem to track down the right filter to process this in just yet (where the edit form is being saved), especially since attachment_fields_to_edit can be used in multiple places. But maybe you already know? This will give you a good start anyway... add_filter('??attachment_fields_save_filter??','move_attachment_directory',10,2); function ...


0

The other pages show a 'current menu item' css state: .nav-menu .current_page_item > a, .nav-menu .current_page_ancestor > a, .nav-menu .current-menu-item > a, .nav-menu .current-menu-ancestor > a { color: #bc360a; font-style: italic; This page is showing as 'page-id-32'. If that corresponds to the page in the menu it should show the ...


2

What you found is actually perfectly accurate. With WP's commitment to backwards compatibility it's not that common for thing to stop working. This filter is used in wp_set_auth_cookie() to calculate the duration. Resulting value is used in PHP's setcookie(). There is no mention of specifics limits in documentation, so in practice the value is limited by ...


2

Make use of custom parameter, lets call it wpse__current_year, which will accept two values, true (includes current year) and false (excludes current year). Lets incorporate that function show_monthly_archive( $post_type ) { $current_year_args = array( 'type' => 'monthly', 'limit' => '12', ...


0

i got a answer from another thread.. which is bellow add_filter('nav_menu_css_class', 'discard_menu_classes', 10, 2); function discard_menu_classes($classes, $item) { $classes = array_filter( $classes, create_function( '$class', 'return in_array( $class, array( "current-menu-item", ...


0

I think this may be what you need - customizing feeds Feed templates are in wp-includes. It's pretty straight forward from there to edit a loop to exclude a post or create a new feed template for the custom post type.


0

I think !isset is a more reliable way of testing so I added that: add_filter( 'registration_errors', 'odin_registration_errors', 10, 3 ); function odin_registration_errors( $errors, $sanitized_user_login, $user_email ) { if ( !isset( $_POST['role'] ) || empty( $_POST['role'] ) || trim( $_POST['role'] ) == '' || ...


2

Why not get all post_types and loop through them with the filter. This should work if the callback for all post types is the same (managesortablecolumns). The code will look something like this: function init_managesortablecolumns (){ $post_types = get_post_types(); foreach( $post_types as $post_type ){ add_filter( 'manage_edit-' . ...


0

You need to do a couple of things. To find new comments you need to be tracking visitiors. If you're capturing last login time that'd be great. Then you need to edit your template to check your comments before dissplaying the content. Alter you comments query and here and if there's new comment since the last login add a class to the post div element. In ...



Top 50 recent answers are included