Tag Info

Hot answers tagged

3

Sometimes you want to run some code before deciding to add an action, or a filter. This may involve checking the user's permissions, checking the type of page request, checking whether another plugin is active etc. Some of those checks may not be possible until some way through WordPress' execution - so it's reasonably common to do that work in an init ...


3

There are several hooks in get_the_post_thumbnail for example begin_fetch_post_thumbnail_html end_fetch_post_thumbnail_html /wp-includes/post-thumbnail-template.php You could add a function to one of these actions which removes your filter on first run. If you need further help with this please add some code how you filter the_content.


3

'the_posts' is an action fired everytime WP_Query get posts, for main query and for other secondary queries, so when you do something like: $foo = new WP_Query($args); in a widget or elsewhere (shortcode, related posts...) 'the_posts' is triggered again. However there is only one main query, so you can use a conditional and do what you do only if the ...


2

You should first load your scripts with a hook on wp_enqueue_scripts like this for example : add_action( 'wp_enqueue_scripts', 'load_my_scripts' ); function load_my_scripts() { wp_enqueue_script( 'jquery' ); } What I like to do is, register my script with a hook on init and then enqueue them with a hook on wp_enqueue_scripts: // Register Scripts ...


2

Scripts and stylesheets should always be loaded in the head or in the footer via the wp_enqueue_scripts action hook. wp_enqueue_scripts is the proper hook to use when enqueuing items that are meant to appear on the front end The init hook executes before wp_head which is to early for script to load in the header. The wp_enqueue_scripts action hook is ...


2

If necessary it is easier to remove one function from init than two (or maybe fifty) from all over. It is commonly recommended to not run anything before init hook in general, so that's typical starting point even when it isn't forced by required technical implications.


1

The problem is that you can't distinguish form an anonymous function and another, so yes, it is possible to remove a closure (i.e. anonymous function) but if more than one closure act on same filter at same priority you have to make a choice, remove them all, ore remove only one (without knowing exactly which). I'll show how to remove them all using a ...


1

In your code, you are executing get_post_types() before the post type is registered. Try, for example, this: function test(){ $args = array( 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'exclude_from_search' => true, ...


1

setup_theme run on init theme, before after_setup_theme. The follow order on frontend, was fired in my test: load_textdomain plugins_loaded auth_cookie_valid set_current_user sanitize_comment_cookies setup_theme after_setup_theme init



Only top voted, non community-wiki answers of a minimum length are eligible