Want to use wp_get_current_user() in query filter

since the query filter is “applied to all queries (at least all queries run after plugins are loaded)” as stated here in the wordpress codex you should do a further test to make sure that you are in the query you want to be. Perhaps a certain query or queries is/are run before the one(s) … Read more

Insert Content Before div#main from the functions.php File

The markup surrounding the content is not specified by WordPress, so there is no hook for that. But you can declare your own hook there. In your template file, write … <?php do_action( ‘before_content_container’ ); ?> <div class=”main”> <?php the_content(); ?> </div> <?php do_action( ‘after_content_container’ ); ?> … and then you can register a callback … Read more

Is it possible to use add_filter in an included file in the child theme’s functions.php?

What you’re trying to do is possible. When including php files, use get_stylesheet_directory() in child themes and get_template_directory() in parent themes. E.g. require_once( get_stylesheet_directory() . ‘/inc/myfile.php’); get_stylesheet_directory_uri() and get_template_directory_uri() will return URLs. Those functions are useful when enqueuing public assets such as stylesheets and JavaScript. Also, setting allow_url_include to Off in your php.ini will provide … Read more

Remove post type filter added by the plugin in the final query

The best course of action would be to prevent the plugin from doing something you don’t want. If for some reason this is not possible you can use the filter pre_get_posts to change the query before it is executed, like this: add_action( ‘pre_get_posts’, ‘wpse239465_force_post_type’, 9999); function wpse239465_force_post_type () { $query->set(‘post_type’, ‘mycustomepost’); } Note that this … Read more

Include HTML (Bootstrap Modal Box) with a plugin into my header

You only need the_content filter to add the modal, but bootstrap.js is needed to make it work. add_action(‘wp_enqueue_scripts’, array($this, ‘enqueue_bootstrap’); public function enqueue_bootstrap(){ wp_register_script( ‘bootstrap’, plugins_url( ‘your-plugin/assets/js/bootstrap.min.js’ ) ); wp_enqueue_script( ‘bootstrap’ ); } EDIT: You need to add $content argument to your function. As the codex says Note that the filter function must return the … Read more

Functions Filter Question [closed]

this is for Variable scope. A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function: $meinungen = Test; // is in global scope function wpseo_set_title_callback($input) { if (is_single()) { … Read more