Add something to beginning of the content

the_content is also a filter, into which the content is passed as an argument. You simply prepend your content and then return like so. add_filter(‘the_content’,’prepend_this’); function prepend_this($content) { $content = “string to prepend” . $content; return $content }

Cron jobs in a class

I was working with wp_cron last week in a plugin and we have a fight and are no longer on speaking terms, but for reference this is what I do; 1) – set the scheduled cron event on register_activation_hook 2) – remove the scheduled cron event on register_deactivation_hook If you are concerned that your scheduled … Read more

Difference between do_action(‘admin_enqueue_scripts’, $hook_suffix) and do_action(“admin_print_styles-$hook_suffix”) syntax

For … do_action(‘admin_enqueue_scripts’, $hook_suffix); … the callback gets the hook suffix as first parameter. Since it is an action you don’t have to return anything. You can use it in a rather flexible callback function: add_action(‘admin_enqueue_scripts’, ‘wpse_49993_admin_script_callback’ ); function wpse_49993_admin_script_callback( $hook_suffix ) { switch ( $hook_suffix ) { case ‘index.php’: // dashboard // do one … Read more

Unable to prevent function using save_post firing twice

First, you can use this hook to target only one custom type: https://developer.wordpress.org/reference/hooks/save_post_post-post_type/ This hook (and save_post) is called the first time when you click on “new …” and then the hook is called with $update = FALSE. Then to send e-mail only when the object is updated, you can test $update like this: const … Read more

How can I find out what functions are assigned to actions?

There is a magic action all which is called on every action or filter. You can hook into this action and log all associated functions. In $GLOBALS[‘wp_filter’] which you can inspect too you can find all active hooks, eg. hooks that are actually used. I have written a small plugin T5 Debug Hook to see … Read more

remove_action in a theme

Your remove_action has to have a priority matching the priority used in add_action. Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure. http://codex.wordpress.org/Function_Reference/remove_action In you case, it looks like remove_action(‘wp_head’, ‘theme_metas’); should … Read more

When is admin_init Action ran?

From the Codex: admin_init is triggered before any other hook when a user access the admin area. This hook doesn’t provide any parameters, so it can only be used to callback a specified function. So yes, it’s run on every admin page load.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)