Articles of hooks

wp_ajax action is not running

I’m writing a plugin. I want to run the method get_my_option when someone pressing a button in the settings page of my wordpress plugin. The ajax call is made but the method never runs. In the page I have the following code: <div class=”wrap”> <input type=”button” value=”test” onclick=”my_js_function();”/> </div> <?php wp_enqueue_script( ‘function’, plugins_url( ‘/js/synchandler.js’,__FILE__), array(‘jquery’)); […]

Can I remove WooCommerce main content hook?

<?php /** * woocommerce_before_main_content hook * * @hooked woocommerce_output_content_wrapper – 10 (outputs opening divs for the content) * @hooked woocommerce_breadcrumb – 20 */ //do_action( ‘woocommerce_before_main_content’ ); ?> For now, I’m just commenting it out to disable before main content and after main content. Is it possible to do it without modifying the plugin files? <?php […]

Edit admin post page

I have to customize the admin page where you edit the other pages “wp-admin/post.php”. I have to add a lot of things, and delete others, change colors and add a custom menu to the top. I don’t know how to start searching for this. Are there any hooks, or funtions to change the HTML in […]

Hook to generate a dynamic sitemap with “All in One SEO Pack” Plugin

Besides the urls of posts, pages and categories, I need my site’s sitemap to include the urls of various pages that display data coming from an external source other than the WP database (Rails API). Is there a hook to which I can add a filter so that once Dynamic Sitemap Generation takes place, I […]

How to change Woocommerce breadcrumbs content?

I want to customize the breadcrumbs directly from PHP. Some of the pages are generated dynamically and do not exist in the database, therefore i must automatically put them in the breadcrumbs with some sort of PHP script. I don’t need to change default stuff, like homepage url, separators, etc…but i actually need to manually […]

Using wp_ajax and wp_ajax_nopriv hooks

I want to send an ajax request and want to process it if the user is logged in. Therefore I want to use following two hooks, but I am not sure if I am using them correctly. Is it correct to use same function take_action_function for the both hooks, and then check in the function […]

Show modified time if post is actually modified

I want to display post updated time only if post is modified, I am using function the_modified_time() . So I just read about that there is if statement that can be used to check if post is even modified that looks like this: if (get_the_modified_time() != get_the_time()) So I put this in my template where […]

Hook into wp_head(); in a plugin

I am following a tutorial that requires I put this code above wp_head(); <?php $example_position = get_theme_mod( ‘logo_placement’ ); if( $example_position != ” ) { switch ( $example_position ) { case ‘left’: // Do nothing. The theme already aligns the logo to the left break; case ‘right’: echo ‘<style type=”text/css”>’; echo ‘#main-header #logo{ float: right; […]

How to find hooks as per Just-In-Time approach?

How can I follow Just-In-Time approach in hooking up my function to an action? I mean everybody just attach the functions to a very early stage like init which leaves the scope of optimisation. I saw in a Wordcamp presentation once that JIT will yield some performance and I totally agree with it but how […]

How to properly add function called by action-hooked function to functions.php?

I am modifying my main queries with a function, modify_main_query($query), that determines which page is being accessed by the user via if/else statement, and then modifies the query accordingly. I am adding that function using this hook: The main function’s hook add_action(‘pre_get_posts’, ‘modify_main_query’) One of my if clauses (for a certain page) inside of modify_main_query($query) […]