New answers tagged

0

After some experimenting I came to the following suggestion: could it be, that the <title> tag is "hard coded" inside your parent theme's header.php? If that is the case, you could try to remove the <title> tag from your child theme's header.php (copy your parent's header.php into your child theme folder) and then add the theme support back ...


1

Having read your post from top to botom and bottom to top, you have in all probabilty a filter that is passing a title through the pre_get_document_title filter. The clue here the following statement: I've also tried pre_get_document_title, which does fire on page load, Looking at the soure code for wp_get_document_title(), we see the following code: ...


0

The function is_admin() is available before any plugin is loaded. So you can use it when you are registering the callback: is_admin() or add_filter('acf/load_value', 'word_swap' );


2

You need the !is_admin() check. This will return false on admin pages, failing your condition. On front end pages, that condition will return true, executing your conditional statement if ( !is_admin() ) { // Do something only on frontend }


0

If the parent theme does not declare support for title-tag you can do it like this in child theme /** * Theme support should be added on `after_setup_theme` */ function add_theme_support_child() { add_theme_support( 'title-tag' ); } add_action( 'after_setup_theme', 'add_theme_support_child', 11 ); Filter document_title_parts expected return type ...


0

Take a look at kfriend's solution here...it works. Not sure if it carries any other risks but it does work. http://stackoverflow.com/questions/772510/wordpress-filter-to-modify-final-html-output You can pretty much replace anything with anything else, using this.


0

There is no "filter everything" function. WordPress does something with their capital_P_dangit() function that attaches to 'the_title', 'the_content', and 'comment_text'. https://developer.wordpress.org/reference/functions/capital_p_dangit/


0

The default fallback in wp_nav_menu for a menu that doesn't exist/isn't registered is wp_page_menu, which unfortunately does not support the same arguments/implement the same level of "customisability" - you either need to create a custom fallback, or remove the fallback entirely (so that the user is forced to set a menu).


0

Going through its normal proceedings Wordpress will already have evaluated wp_head by the time it gets to the widgets. The dynamic_sidebar_params filter will only be called then as well, so it will also be of little help to get your css in the head. Here's something I wrote about this issue earlier. To include information from widget settings in the head, ...


0

You can indeed add a filter to get_next_posts_link, but it has a different name, namely next_posts_link_attributes Complete code would look like this: add_filter('next_posts_link_attributes', 'wpse_230552'); function wpse_230552() { return 'class="iamclass"'; }


0

It looks like the filter's name is next_posts_link_attributes but not get_next_posts_link as that the name of the function. So try instead: add_filter( 'next_posts_link_attributes', 'wpse_next_posts_link_attributes' ); where wpse_next_posts_link_attributes() is your filter callback. Example (untested): function wpse_next_posts_link_attributes( $...


0

You've got the $content available to you in your remove_p function - so inside that function just look for the existence of a special string (i.e. your "shortcode"), to allow the filter to do the str_replace. For example: if ( false !== strpos( $content, "[p-filter]") ) { $paragraphs = array("<p>","</p>","[p-filter]"); $...


-1

WP SEO execute the add_filter( 'the_content', 'cpt_template' ); multiple times and override the content.


4

There are e.g. the following dynamic sanitize_term_fields() filters: edit_term_{$field} filter for the edit context pre_term_{$field} filter for the the db context term_{$field}_rss filter for the the rss context term_{$field} filter (default) and also the taxonomy-specific ones: edit_{$taxonomy}_{$field} filter for the edit context pre_{$taxonomy}_{$...


0

Your code is working exactly as it should. The style_formats filter allows you to add additional styles via class names. It is perfectly valid for an element to have multiple classes (and is not limited to only two). I've been working with the tinymce editor for years; and I can honestly say I have no idea what the "exact" argument does, exactly. I have ...


4

Your analogy here is partially correct, but incomplete: I understand that when do_action is called wp looks for all registered listeners and invokes them according set priority. You need to consider what happens when you call add_action. WordPress never searches for the add_action statements, it has those in a list. When you call add_action, it ...


0

All your actions belong in your functions.php, assuming that you are building a theme. It is here that you add actions to certain events in your templates. Now, once it has read functions.php WP has a list of actions it is supposed to undertake at certain points in your theme templates. There are several predefined action hooks, such as wp_head() and ...


0

Since version 4.9 visual composer added shortcode lazy loading. To use VC shortcodes on AJAX content use this function before printing the content WPBMap::addAllMappedShortcodes();. So below code may help you, function get_page_content(){ $id = $_REQUEST['id']; $page_data = get_page($id); WPBMap::addAllMappedShortcodes(); echo ...


1

Off the top of my head - put this in your functions.php: add_filter( 'infinite_transporter_in_same_cat', '__return_false' );


4

You do not need to create a complete new widget to do what you need to do. As I read your question, you are just interested in changing how the categories are displayed on the front end. There are two functions that displays the categories on the front end wp_list_categories() which displays the categories in a list wp_dropdown_categories() which displays ...


4

You can override the default WordPress widgets by extending them. The code for the default Categories widget can be found on the following link: https://developer.wordpress.org/reference/classes/wp_widget_categories/widget/ and below is an example code how you can override the output of the widget. Class My_Categories_Widget extends WP_Widget_Categories { ...


7

To expand on Mark's answer, there's not much (generally) available in the way of filters in the default WordPress widgets (except for perhaps widget_text). But adding your own custom widget is easy - put this in your functions.php: require_once("my_widget.php"); add_action("widgets_init", "my_custom_widgets_init"); function my_custom_widgets_init(){ ...


1

image_make_intermediate_size was not the hook I was looking for, but intermediate_image_sizes_advanced. Here is a working code: function disable_upload_sizes( $sizes, $metadata ) { // Get filetype data. $filetype = wp_check_filetype($metadata['file']); // Check if is gif. if($filetype['type'] == 'image/gif') { // Unset sizes if ...


1

currently there is no good tool for resizing animated gifs Resizing of animated gifs is supported by ImageMagick, which happens to be the default image library of WordPress. The only thing is WP doesn't support this filter in its default API to ImageMagick. Fortunately, it is possible to intercept image_make_intermediate_size, the hook that produces the ...


0

This is not something that WordPress can easily do. You can think of pagination in WP as sliding window that shows fixed size part of one large query. It can be at start of the query or at the end, but it relies on it being same query. This doesn't nearly work when the size and number of the page are subject to variable logic like this. I had recently ...


2

The action name suggests it is run _after_the_content, not within the the_content itself, so you might have to do something different here like @SamuelElh is suggesting... You would add a function to the action with early priority to buffer, then add a filter to the final output with a late priority: add_action('tribe_events_single_event_after_the_content',...


2

The dynamic filter "term_{$field}" is probably what you're looking for, where the field is "name." One approach is to have an array of names and their pseudonyms, then do a check-and-return on them so they'll display the replacement. add_filter( 'term_name', function( $value ) { $terms = [ 'old' => 'new', ]; // basic example check, ...


1

The top answer (from 4 years ago) no longer works, but the WordPress codex has the solution here: <?php function add_posttype_slug_template( $single_template ) { $object = get_queried_object(); $single_postType_postName_template = locate_template("single-{$object->post_type}-{$object->post_name}.php"); if( file_exists( $...


0

The WordPress admin area uses capabilities to determine which user role can see what pages etc. You can use custom written code or several plugins to control to capabilities by each user. I'd suggest using the Members plugin for some easy control.


0

Contrary to the comments... I'd say that you should use filter as in method 1 because... Message will depend on quite a few things right now, You just do a test if statement, later on message may depend on some other factors ( like maybe validating a nonce on failure giving message 'None invalid' ). Actions help in extending your code's functionality... ...


0

Start by browsing to Appearance – Menus. Select the menu where you want the link to be displayed. Create a new Link menu item and use # as the URL with the link text of categories. Then click the Add to Menu button. Select which categories you want to be displayed within the dropdown list. After you add the categories to the menu, make sure to drag and ...


0

The get_avatar filter accepts 6 parameters, not 5. The $id_or_email can also be an instance of WP_Post, WP_User or a md5 hash string. So it's better to extract $user_id like this: if ( is_numeric( $id_or_email ) ) { $user_id = $id_or_email; } elseif ( is_string($id_or_email) ) { if ( is_email($id_or_email) ) { $user = get_user_by('...


3

Why to edit the whole form ? Filters are good because they gives you the current output and you just need to add your string to it then return it back to WordPress. In above example you are not using it so let use it. Example:- add_filter('the_password_form', function( $form ){ $my_html = '<h2><br>Password Protected Area</h2>'; ...


0

@SamuelEth is right, creating a page to handle this (with rewrites) could be the way to go. Another alternative would be registering a custom post type of my-plugin(with the admin UI setting off since you don't want user access to it)... ...and dynamically detecting and handling calls to that, the advantage being the rewrite is done for you somewhat. ...


0

this does the trick <?php function add_class_to_term_description($term_description) { echo '<div class="cell">' . $term_description. '</div>'; } add_filter( 'term_description', 'add_class_to_term_description' ); ?>


3

My preference is a special query var that acts as a flag to trigger your filter: function wpse_228386_maybe_batman( $clauses, $wp_query ) { if ( $wp_query->get( 'iamthebatman' ) ) { // Fight crime } return $clauses; } add_filter( 'posts_clauses', 'wpse_228386_maybe_batman', 10, 2 ); Now you can "activate" it anywhere you like, ...


4

I wonder if you could override the [rev_slider] with this kind of wrapper: add_shortcode( 'rev_slider', function( $atts = array(), $content = '' ) { $html = ''; // Your custom banner HTML $banner = '<div id="bannerHTML"><!-- banner HTML goes here --></div>'; // Append your banner HTML to the revslider's output if( ...


2

This is a solution I've come up with after refining it a bit. The below should only run if the shortcode exists in the content. It loops through all the shortcodes to find the specific one we need, replaces it with the shortcode plus the new HTML: function insert_after_shortcode( $content ) { if( ! has_shortcode( $content, 'shortcode_name' ) ) { ...


7

The dialog HTML comes from WP_Editors::wp_link_dialog() but no hooks in there. We could instead use jQuery to append the custom HTML to the link dialog and try to override e.g. the wpLink.getAttrs(), because it's very short ;-) Demo example: jQuery( document ).ready( function( $ ) { $('#link-options').append( '<div> <...


2

Looking at the core, there's no trace of any filter or action in the wp_link_dialog function, which would have made your life easier... Investigating how others has solved this problem, there's a plugin that does more or less the same as you want. Basically it deregisters the wplink.js, wp_deregister_script('wplink'); and registers again a modified version ...


0

So I found the solution to my problem. It is because WordPress inserts the dropdown both at the top of the list of users and on the bottom. So when i submit the form, it is the dropdown at the bottom of the page that is being used in the GET and overwriting the one at the top. To solve this issue I just removed the bottom dropdown with a line of javascript ...


1

I found an exact solution I'm looking for. function my_comment_link_filter( $link ) { $link = str_replace( get_permalink() , $custom_permalink , $link ); return $link; }; add_filter( 'get_comment_link', 'my_comment_link_filter' ); It does exactly what I am looking for: It replaces the Page Permalink with the dynamic permalinks when I call the ...



Top 50 recent answers are included