Articles of filters

Insert Content Before div#main from the functions.php File

I know WordPress has a filter for targeting the content in the functions.php file: add_filter( ‘the_content’) However, is there a filter to insert content BEFORE ? ‘the_content’ filter puts content AFTER div#main. I’m looking for something like: add_filter( ‘before_main’) Does a filter like that exist?

Admin: how to make a custom list filter button send GET queryvars

I’ve setted custom columns for a custom post type, and I want to add a filtering functionality. I need to use custom data, so I can’t take advantage from things like wp_dropdown_categories and the like. My current code: // add select function add_filter_by_macroarea() { global $typenow; $post_type = ‘distributor’; $macroaree = array(‘italy’,’france’,’spain’,’world’); if($typenow == $post_type) […]

change “missing attachment” text functions.php

WordPress core file: wp-includes/post-template.php has this text “Missing Attachment” that i want to change with “-“. The problem is that when WordPress upgrades, the file is changed back to the old “Missing Attachment” text. So, are there any filters I can use in my functions.php to do that?

tiny_mce_before_init: 'exact' => true has no effect

For a custom theme, the editors want to be able to select three different font sizes in the post editor. I thought about using a standard font size plus defining two extra classes: <p class=”bigger”> and <p class=”smaller”> Therefore I define the following formats in tiny_mce_before_init: $style_formats = array( array( ‘title’ => ‘bigger paragraph’, ‘block’ […]

How to allow users to view pending posts of a specific custom post type?

I have a form on the front end that allows users to post a custom post type. The posts enters the database as pending for later moderation, how do I allow users to view these posts on the front end? Currently I get a 404 because it is in pending status, but in this case […]

How to filter Sidebar Content

I want to filter sidebar content generated from dynamic_sidebar() and only return the last 2 calendar years of archives (not last 24 months). Is it possible to do this sort of filtering and how?

Is it possible to use add_filter in an included file in the child theme's functions.php?

I am trying something basic but I can’t seem to figure it out or I am not even sure if it is possible to be done in a child theme. What is am trying is to organize the the codes in the functions.php file in the child theme by creating a separate directory for include […]

How to filter url on post submission?

I would like to swap out image URLs upon post submission on both content editor field and a custom field cover_image of a custom post type article. For example, the original content may contain image url such as: <img src=”http://img.mywordpresstips.com/custom-post-types/filename.jpg”> I would like to swap it to: <img src=”http://img.mywordpresstips.com/custom-post-types/filename.jpg”> And have it stored permanently to […]

apply_filters with multiple args and multiple add_filter

I’m using apply_filters to bridge the gap between plugins but am struggling with the arguments. There is one argument, an array, there are several implementations of add_filter to match apply_filters and each of them pass down the original array and add to it. Seems that you can pass several arguments from apply_filter but add_filter can […]

Problem with images URL after filter applying

I have this code in my functions.php file: function user_content_replace($content) { // it’s not a URL, let’s apply the replacement if (!filter_var($string, FILTER_VALIDATE_URL)) { $replacement = ‘$1.</p><p>$2’; return preg_replace(“/([^\\.]*\\.[^\\.]*\\.[^\\.]*){1}\\.([^\\.]*)/s”, $replacement, $content); } else { // it’s a URL, just return the string return $content; } } add_filter(‘the_content’,’user_content_replace’, 99); This code replaces every third dot in […]