Articles of init

Load ajax if is_home()

I want to show some simple things on homepage with ajax. The problem is I want to load everything when is_home() is true. Php, js, everything. In funtions.php: add_action(‘init’, ‘pint_functions_separation_test’); function pint_functions_separation_test(){ if ( is_home() ) { require_once(‘functions_hometest.php’); } } functions_hometest.php: <?php if (file_exists(“./wp-load.php”) && file_exists(“./wp-blog-header.php”)){ define(‘WP_USE_THEMES’, false); require_once(“./wp-load.php”); require_once(“./wp-blog-header.php”); } add_action( ‘wp_ajax_nopriv_ajaxtest’, ‘ajaxajaxtest_handle_request’ ); […]

WordPress Plugin Boilerplate – add_action hook in static “activate” function

I’m hoping someone can point me in the right direction here. I’m using the WordPress Plugin Boilerplate to develop a custom plugin. On install, the plugin will register a new post type (course), a new taxonomy (course-areas) and set up permalink structures for the new post type and taxonomy. I’ve added my code (to create […]

Stop WordPress Entirely and Run My Own Code

I have a site that must be deployed in a WP Multisite environment but none of the code in the site uses WordPress at all. How can I intercept WordPress, perhaps at ‘init‘, and tell it to stop doing anything and let me take over? I tried just putting everything in my index.php file and […]

How to insert a text in all pages and posts before or after specific places?

I have this simple code below: function func1() { echo “this is amazing”; } add_action(‘reko_hook’,’func1′); Now, I know that I could use reko_hook(); either inside index.php or page.php where I want, but I was wondering if there are more pre-defined hooks such as ‘init‘. For example, I could do add_action(‘init’,’func1′); but it will echo this […]

Cron While Editing Post

I have a multi-author blog, on which there are two schedule cron functions. The first function moves all public posts in the pending status after 365 days: if( ! wp_next_scheduled( ‘expire_posts_hook_publish’ ) ) { wp_schedule_event( time(), ‘hourly’, ‘expire_posts_hook_publish’ ); } add_action( ‘expire_posts_hook_publish’, ‘expire_posts_publish’ ); function expire_posts_publish() { global $wpdb; $daystogo = “365”; $sql = “UPDATE […]

Using get_terms for custom taxonomy in functions.php

I`m trying to retrieve the names of taxonomy items and include them into a theme admin panel. function retrieve_my_terms() { global $terms; $terms = get_terms(‘taxonomy’); foreach ($terms as $term) { $option = $term->name; return $option; } } The function is added after the functions which created the custom post type and taxonomy. From what I’ve […]

add_feed and flush_rewrite_rules

There seems to be quite a controversial opinion on the WordPress flush_rewrite_rules() function. According to the Codex, it is highly discouraged to use this function on the init action hook. However: In a plugin I am working on, I am using add_feed() to, well, add a feed. The Codex says that this should be run […]

Change page title from plugin

Is possible to change page title on the fly from plugin? I’ve try global $post, but seem like plugin runs after. Any Ideas? Edit: Im writting some pages on the fly, based on same page / post, so every page show the same title. Looking a way to do via shortcode or writting my own […]

Are there any action like 'init_frontend'

I’ve found init and init_admin. Are there any action that executes just in the frontend? Thanks.

WordPress Theme activation hook?

I know the many tricks to see if said theme is activated, I have scoured the internet. I am not looking for re-pasting of that code. What I am looking for though is weather or not 3.3-3.5 released a new function that does something upon theme_init, I saw some sort of hook, but I can’t […]