Articles of filters

Add Content Exclusively to a Custom Post Type Feed

Introduction If I wanted to add some content at the end of an RSS feed entry, I could write something like this: // quick PHP 5.3+ example add_filter(‘the_content’, function($content) { // If this is not a feed, leave now. if ( !is_feed() ) return $content; // Add content to the feed entry. $content .= ‘Thank […]

Add a header before fields added with the attachment_fields_to_edit() filter

Just wondering if it’s possible to add a header before fields added with the attachment_fields_to_edit() filter, just like the one before the attachment display fields. Any ideas? Thanks PHP: function my_attachment_fields_to_edit( $form_fields, $post ) { $form_fields[‘attachment-url’] = array( ‘label’ => __( ‘URL’, ‘plugin’ ), ‘input’ => ‘text’, ‘value’ => get_post_meta( $post->ID, ‘_attachment_url’, true ) ); […]

How To Get User Data in Callback Function for pre_user_nicename?

Whenever I update a user profile in the dashboard, the user nice-name gets changed in the database: Every time, a “-2” is added. I tried to reset the nicename (based loosely on this thread) by hooking into edit_user_profile_update and personal_options_update, but that seems to be to early, the value does not change: add_action( ‘personal_options_update’, ‘my_reset_nicename_function’ […]

What's the best way to split admin-only functionality in the theme's functions.php file?

I am customising a WordPress admin area and so far so good with a number of add_filter and add_action calls in my theme’s functions.php file. But I’m a bit worried because all this code will be executed on all pages, not just the admin area. I therefore went ahead with the below approach: if (is_admin()) […]

is there a specific place where add_filter must be placed?

Most plugins mention adding add_filter to functions.php, but can I use it elsewhere? Does it depend on the plugin? I am trying to use add_filter in a custom template file before get_header(); but it doesn’t look like its being added on time. I guess I am trying to figure out the order of when things […]

Add parent template name to body class filter when visiting subpage or single post

how would I go about creating a filter for the body_class() tag that allows me to add the the parent pages slug name as a class to the body whenever visiting a subpage or post?

How to properly loop through these external URLs to get them into the sitemap using this hook

I have filtered Urls that I would like to add to push into a sitemap. I am using one of the sitemap plugins, which has hooks to further modify it. my code: // add to theme’s functions.php add_filter(‘bwp_gxs_external_pages’, ‘bwp_gxs_external_pages’); function bwp_gxs_external_pages($pages) { return array( array(‘location’ => home_url(‘www.example.com/used-cars/location/new-york/model/bmw’), ‘lastmod’ => ’27/03/2017′, ‘frequency’ => ‘auto’, ‘priority’ => […]

How do I add a listbox to the TinyMCE editor?

I am having trouble adding a list box to the TinyMCE editor in WordPress. I have already read entirely through this question but it did not get me all the way there: How i can i add a split button or list box to the WordPress TinyMCE instance. That solution only alerts the value in […]

How to hook into permalink when publishing-saving post?

I want to know how I can change the structure of the permalink to my desired one before saving or publishing my post in WordPress? For instance, when I add the title like the wordpress blog in my post I get the permalink structure similar to the below: http://localhost/2015/09/10/the-wordpress-blog/ I want to change it to […]

Check if page parent has certain template

I want to check if a page has a parent with a certain page template attached to it. If I know that I can determine which scripts to load or not. Normally I would just get the page template and if it is a match load the scripts needed but now I have the script […]