get_title without filter(the_title)

There’s a few ways to do this, but I would argue that the preferred way is, in general, fetching the post_title attribute from the post object. This does not depend on removing all filters for a certain function and adding them back later — the latter requires you to directly access the global $wp_filter. get_post … Read more

Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?

If you look at the source code, you can see that wp_enqueue_style( ‘crayon’ ) is called in Crayon::enqueue_resources() which itself is called either from either Crayon::the_content() or Crayon::wp_head(). The code in Crayon::wp_head is: if (!CrayonGlobalSettings::val(CrayonSettings::EFFICIENT_ENQUEUE) || CrayonGlobalSettings::val(CrayonSettings::TAG_EDITOR_FRONT)) { CrayonLog::debug(‘head: force enqueue’); // Efficient enqueuing disabled, always load despite enqueuing or not in the_post self::enqueue_resources(); } … Read more

the_content filter – checking the post

You’ll need to rely on the global post variable, or get_post(), which is essentially the same thing. add_filter( ‘the_content’, function( $content ) { $post = get_post(); if ( in_the_loop() && has_category( 123, $post ) ) { // etc. } return $content; } ); I included a check for in_the_loop(), because the the_content filter is commonly … Read more

Using Conditional Statement in functions.php

Basically, you put the second block into the first. And wait until the last moment: add_action( ‘pre_get_posts’, ‘wpse_71899_start_filter’ ); function wpse_71899_start_filter() { // wrong page if ( ! is_page( ‘Home’ ) ) return; // stop here. add_filter(‘posts_orderby’, ‘edit_posts_orderby’); add_filter(‘posts_join_paged’,’edit_posts_join_paged’); } function edit_posts_join_paged($join_paged_statement) { global $wpdb; $join_paged_statement = “LEFT JOIN “.$wpdb->prefix.”wpv_voting ON “.$wpdb->prefix.”wpv_voting.post_id = $wpdb->posts.ID”; return … Read more

Where can you find the available filter tags?

There are multiple was to find filters: Use an IDE (see Eclipse example), set WordPress as a separate project and search in this project for apply_filters or do_action. Get a program to search in all files of a directory (grep, Notepad++) and do the same search with that. Read the source code. If you start … Read more

Editing

Yes, it is possible. You can use the_content hook and assign your own filter to this hook. Then you should (that is the part when things get a little bit messy) parse and replace content of that post. So for example you can do it like so: function my_the_content_filter($content) { $content = str_replace(‘<h2 ‘, ‘<img … Read more

Yoast SEO hooks overriding themselves

Filters should be returned even if your condition fails. You are currently just returning the output when your condition is met, not when it fails. return $string; at the end of each function should solve your issue. EXAMPLE add_filter(‘wpseo_canonical’, ‘listpagecanonical’); function listpagecanonical($string) { if (is_page(1)){ //I do my stuff here return ‘http://canonicalurl.com’ } return $string; … Read more

How do I filter title and alt attributes in the gallery shortcode?

The shortcode is parsed by gallery_shortcode(), which calls wp_get_attachment_link(), which in turns calls wp_get_attachment_image(). This latter function writes the <img> tag with the title attribute. You’re lucky, because the attributes are filtered through wp_get_attachment_image_attributes, so you can hook into that and remove the title. To do this, you attach the hook before you call the … Read more

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