Inject class in body when particular page template is used

there is a filter for that and it’s called… body_class 😉 This should work for your case: function add_my_custom_body_class( $classes ) { if ( is_page_template( ‘page-customer.php’ ) ) { $classes[] = ‘body_customer’; } return $classes; } add_filter( ‘body_class’, ‘add_my_custom_body_class’, 10, 1 ); if you wanna add class based on page ID (as you’ve mentioned in … Read more

Copyright info change – Corporate Plus Theme PHP [closed]

Both functions check if the function corporate_plus_footer() exists. If not, one is defined. Without going deeper into hooks and filters, you can simply declare your own corporate_plus_footer() and the other won’t get loaded. Add this to your functions.php function corporate_plus_footer() { echo ‘it works’; } No additional add_action() or similar. Just this function in your … Read more

How to get Post Type from the functions.php file

You have to create the function and call it when post ID is already set. Otherwise it will be empty. E.g. wp_head meets this requirement, init is too early. function my_selective_wpautop() { global $post; if( is_singular() ) { if( ‘page’ == $post->post_type ) { remove_filter( ‘the_content’, ‘wpautop’ ); } elseif ( ‘post’ == $post->post_type ) … Read more

Inline style to PHP [closed]

Why not add a CSS class to the H1? echo ‘<h1 class=”custom-style”>’ . get_the_title() . ‘</h1>’; then in your child theme or custom CSS, apply the style to that class: h1.custom-style { text-align:center; color:#fff; font-size:60px; }

get href content [closed]

I find the DOMDocument() class handles this elegantly. This snippet of code should help you (put the entire html tag including the div wrapper in the $tag variable): $d = new DOMDocument(); $d->loadHTML($tag); $a = $d->getElementByTagName(‘a’); $href = $a->item(0)->getAttribute(‘href’); The $hrefvariable will have the attribute value of href.

Issues when changing == to ===

The get_theme_mod() function could return an explicit false. The === operator looks for exact matches, so in the case of hide_logo not being set the function would return false and false is not an exact match to an empty string ”. The == operator is a bit more forgiving in that sense which is why … Read more

Conditional tag doesn’t work in WordPress plugin

Both those hooks are too early to use is_page(). WordPress hasn’t determined which page is being loaded yet, so it can’t check the current page. Try template_redirect for both: /** * Plugin Name: Test1234 */ function replace_image_content(){ if ( is_page( ‘img’ ) ) { header( ‘Content-Type: image/jpg’ ); $image = plugin_dir_url(__FILE__) . ‘1404-1.jpg’; readfile( $image … Read more

List posts that don’t have a specific tag?

I believe you can filter them out in your original WP_Query using Taxonomy Parameters. Then you can delete the for loop altogether. $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ =>-1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_tag’, ‘field’ => ‘slug’, ‘terms’ => array(‘fun’,’learning’), ‘operator’ => ‘NOT IN’, ), ), ); $wpb_all_query = new WP_Query( $args … Read more

Hide Featured Image Meta Box on Editor Screen

I tested it myself with the code you use and it only works with Gutenburg disabled. It seems to be related to the new editor. Assuming you want to use the new editor, and depending on your theme and plugins this code may work for you (it worked from my tests): add_action( ‘after_setup_theme’, function(){ // … Read more