Tag Info

New answers tagged

0

Yes. you can do that. function my_custom_footer() { ?> <div class="site-footer-logo"> <img src="<?=get_stylesheet_directory_uri();?>/images/my-logo-small.png" alt="My Logo Small" /> </div> <?php do_action('my_own_hook'); ?> <p>Copyright &copy; <?=date('Y');?>, my-url.com.</p> ...


0

I checked how ACF did it and tried it their way, worked for me. class Directory_Post_Type { public static $post_type = "directory"; public function __construct() { add_action( 'init', array( $this, 'init' ) ); add_action( 'admin_init', array( $this, 'admin_init' ) ); add_filter('post_updated_messages', array( $this, ...


3

Welcome to WPSE Ittikorn! Sometimes it is the easiest to just look right at the source. There even is a link right at the bottom of the Codex page you linked: https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/link-template.php#L1112 There you can easily see that there actually is a filter called post_type_archive_link So to give you an ...


3

Just look at the source of get_post_type_archive_link(): return apply_filters( 'post_type_archive_link', $link, $post_type ); Sidenote: The function uses home_url(), which is a wrapper for get_home_url(), which offers another filter: return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id ); that runs earlier. With "pretty permalinks" ...


2

The filter is post_type_archive_link, defined (WP 4.1.1) on line 1112 of file wp-includes/link-template.php: apply_filters( 'post_type_archive_link', $link, $post_type ); And the use: add_filter( 'post_type_archive_link', function( $link, $post_type ) { //Do something return $link; }, 10, 2 );


0

Errm, you can't. And more importantly, why would you want to? The whole point of hooks is to open up an API to other developers! You can use a singleton/static flags and/or private methods (called from a hooked public method) if you want to lock down how your plugin can be manipulated. static function myfunction_for_themes() { if ( ! self::$_themes_run ...


1

Your function does not have to accept all arguments, you can not specify the number of accepted arguments and it will default to passing just the first. You can also specify any number up to and including the total number of arguments. For example if you only need the first 2, this will also work: function my_filter_func( $redirect_to, ...


0

Here's an untested example, how you could modify the email body to your needs: add_filter( 'update_welcome_email', function( $welcome_email, $blog_id, $user_id, $password, $title, $meta ) { // Override the email body: $welcome_email = __( 'Dear User, Your new SITE_NAME site has been successfully set up at: BLOG_URL You can log in ...


2

You should be using methods of the $query instance instead of the is_* template tags. And are the categories you are trying to filter a custom taxonomy? cat only works on the default category taxonomy: function wpse_178500_event_type_filter( $wp_query ) { if ( ! empty( $_GET['event_term'] ) && $wp_query->is_main_query() && ...


0

Eventually I did this in the function of my plugin where I was loading my game, $mycredhook = new my_demo_hook_class(); do_action( 'play_game', $mycredhook); Not sure if this is the correct way to go, but it worked.


2

publish_post doesn't work for custom post types, the correct hook (action hook) is publish_{$custom_post_type}. You should use add_action() as this is an action hook. I also tend to make use of the transition_post_status hook which is a much more universal hook as it fires everytime a post's status is changed regardless. You can use $old_status and ...


1

You might want to use the transition_post_status hook instead, for example: add_action( 'transition_post_status', function( $new_status, $old_status, $post ) { if( 'cpt' === $post->post_type && 'publish' === $new_status && 'publish' !== $old_status ) { // do stuff ...


1

The first one does not work because to use that format you need double quotes. add_action( "publish_{$custom_post_type}" , 'run_new_post_code' ); That will let the wrapped variable name be processed properly. To do something for all custom post types you probably just need to grab the list of custom post types and cycle through them adding an action for ...


0

The short answer is that there isn't one. WordPress templating consists mostly of raw PHP and Template Tags API. The API is more focused on outputting specific content, than producing specific HTML. As result the technique is pretty much unknown in WordPress development. It doesn't mean that you can't use one, but it's just not a convention developers ...


2

If you can assume that user profile is edited all at once (Users Role, Organisation ID and Organisation name), you can hook on only one meta_key (say Organisation name) and send all infos at this moment. By the time this action is fired, all 3 metas are already in database. add_action('updated_user_meta', 'when_user_meta_updated', 10, 3); function ...


0

The filter wp_title changes only the function wp_title() when it's called. So, you must double check on your theme's source code if before your header is using wp_title. Anyway, you can set your filter on functions.php. A function to identify your param GET should be something like so: function maybe_change_wp_title_ver( $title, $sep ) { if ( isset( ...


0

If you look at the Action Reference, you can see the order things happen. Note where init is, the query object doesn't exist until the wp action. // ... init └─ widgets_init register_sidebar wp_register_sidebar_widget wp_default_scripts wp_default_styles admin_bar_init add_admin_bar_menus wp_loaded parse_request send_headers parse_query pre_get_posts ...


0

Have your function return your HTML rather than echo it. Perform the logic in the function to see if the image/logo are present and only return the HTML if that's the case, otherwise returning null/false. function my_header_function( $output = false ) { if ( /*image and logo have been uploaded */ ) { $output = /* HTML of your hero header */; ...


1

Once a fucntion has been hooked to an action, the function will be executed every time the action is called (with do_action). To stop this, the action should be removed. See remove_action: function do_entry() { if ( get_the_title() ) { add_action('loop_entry_before', 'function_that_adds_h2_structure'); } else { ...


4

All you can do is bump the priority of your hook: add_action( 'wp_head', 'dns_prefetch', 0 /* Highest priority */ ); but does this put my code just after the start of tag? No, but it will output before any other function attached to wp_head i.e. other <link />'s, most stylesheets, plugin scripts etc. To put it right after <head> you'll ...


0

The ID of the current object is available only after the actual main query has been executed. Also, get_queried_object_id() uses the global $wp_query object; if this object has not been set up, calling some of its methods or properties won't work. So, you must use get_queried_object_id() later. According with the codex, the action hook wp is the first ...


1

Instantiate your object inside a function hooked to the template_redirect action: function wpse_177056_init_shortcode() { new callShortCode(); } add_action( 'template_redirect', 'wpse_177056_init_shortcode' );


-1

do_action is an event and there are many of them throughout your WordPress instance, in the core or your themes and plugins. (Hypothetical) So even when you put an add_action in your plugin file but the theme files are read first by order of execution your add_action function will still fire at that event or time of the do_action it is hooked to. This is ...


1

I was having the same issue recently, until I followed an example from the Wordpress Codex which suggests using action hooks to run the function. I think if you add the following... add_action( 'recalculate_all_scores_hook', 'recalculate_all_scores' ); ...and amend the wp_schedule_event function to use the action hook name rather than the function ...



Top 50 recent answers are included