Articles of hooks

Hook for when a page template is changed

I know that you can remove the editor section of the page editor page ( :/) depending on the template chosen using add_action( ‘load-page.php’, ‘hide_editor_function’ ); (with proper functionality of course). The problem with this though, as you should be able to tell, is that this will only work on a page load/reload. Not as […]

Custom Thickbox Broken on Dashboard Page?

I’m working on an extension that, as part of its functionality, adds Thickboxes to many pages in the WordPress admin. On most pages this works fine — I use an in_admin_footer action hook to call add_thickbox, and include the HTML/Javascript (via an include statement) that includes the Thickbox. add_action( ‘in_admin_footer’, function(){ add_thickbox(); include(__DIR__ . ‘/includes/thickbox-div.php’); […]

Generating robots.txt dynamically

I have a subfolder WP installation. It serves multiple domains, which are linked to the same folder. The requested domain is received in wp-config.php (from the $_SERVER variable) and used to define WP_SITEURL, WP_HOME and DOMAIN_CURRENT_SITE. So we can open the same both from and I need to add the link to XML […]

Modify a function without editing template

I’m wondering how I can modify a function without touching the template file. The following function is called in my theme in the template-functions.php file: if( ! function_exists( ‘book_landing_page_footer_credit’ ) ) : /** * Footer Credits */ function book_landing_page_footer_credit(){ echo ‘<div class=”site-info”>’; esc_html_e( ‘Copyright &copy;&nbsp;’, ‘book-landing-page’ ); echo esc_html( date_i18n( ‘Y’ ) ); echo ‘ […]

Insert term when page is published – avoid duplicates after edits

So i want to dynamically add terms to a custom taxonomy named after new pages when these are published. Problem I have is that when you edit the page titles, another term will be added to the taxonomy. This snippet is from this answer, it works for inserting terms. function add_page_term( $post_ID ) { $post […]

Customizing the default logout page of WordPress

What are the proper filter/hooks to modify the wp-login.php?action=logout confirmation page When you logout of your site using , You will go to a standard page WordPress logout page that has the following text: You are attempting to log out of “Your Site” Do you really want to log out? I do not see […]

add_action for lost_password or modify wp-login.php?action=lostpassword

So far I have completed adding google recaptcha on contact page, login page, and pages that has forms on the front end, all are working great as expected. now only one page is remaining for me to add google recaptcha that is when user clicks on lost your password? link, so I tried adding: add_action(‘lost_password’, […]

Using hooks with extra parameters

I want to add my own function to an already existing hook. Here is the definition: do_action( ‘woocommerce_before_single_product_summary’ ); The original function that uses it looks like so: add_action( ‘woocommerce_before_single_product_summary’, ‘woocommerce_template_single_title’, 5 ); Since I don’t want to touch the theme, nor Woocommerce templates, I want to add my own function but with lower priority […]

Menu item added in wp_nav_menu_items filter is never highlighted

In a Twenty Thirteen child theme I append a menu item (a link to /player-number page template, where the number is different for each user and represents her or his id in a game database) using the wp_nav_menu_items hook: function my_nav_menu_items( $items ) { $profile = sprintf(‘<li id=”menu-item-32″ class=”menu-item menu-item-type-custom menu-item-object-custom menu-item-32″> <a href=”/player-%d/#navbar”>Profile</a></li>’, 42); […]

Executing `createimagefrompng()` from save_post hook (or equivalent hook)

I’m having trouble executing createimagefrompng() from a hook. I’ve used the fairly straightforward PHP way to add a watermark to an image. If I hardcode the image URLs in this function and for example execute it from a page or whatever it seems to work flawlessly, but whenever I execute the exact function from a […]