Plugin CSS not enqueing

If you want to add inline CSS, use wp_add_inline_style(). <?php /** * Plugin Name: WPSE 257470 * Description: WordPress StackExchange question 257470 * Plugin URI: https://wordpress.stackexchange.com/questions/257470/ * Author: Nathan Johnson * Licence: GPL2+ * Licence URI: https://www.gnu.org/licenses/gpl-2.0.en.html */ //* Don’t access this file directly defined( ‘ABSPATH’ ) or die(); if( ! class_exists( ‘wpse_257470’ ) ): … Read more

Input type search in Menu

This is fine, but you if you want things to look “cleaner” and be easier to modify you could instead create a new file menu-search.php and add your HTML there then tweak your function a bit (don’t forget to prefix your functions) function myprefix_add_search_box_to_menu($items, $args) { if ( $args->theme_location == ‘menu-1’ ) { ob_start(); get_template_part( … Read more

Why is file_get_contents returning page source?

Aha, I figured it out! You have to use wp_remote_get(). I’m not exactly sure why at this point, but here’s what the code looks like: function display_csv_data_func( $atts ) { $file_path = “http://example.com/something/file.csv”; $response = wp_remote_get($file_path); $response_body = wp_remote_retrieve_body($response); return “<script>alert(‘” . $response_body . “‘);</script>”; } add_shortcode( ‘display_csv_data’, ‘display_csv_data_func’ );

Menu — How to add “current-menu-grand-ancestor” css class

Something like this will help you filter a menu item and add a custom class conditionally. ( Untested ) function add_nav_class( $classes ) { if ( class_exists( ‘current-menu-ancestor’ ) || $item->title == ‘blog’ ) { $classes[] = ‘current-menu-grand-ancestor’; } return $classes; } add_filter( ‘nav_menu_css_class’, ‘add_nav_class’, 10, 2 );

Creating a related post section based on similar categories

look at the Codex chapters which correspond to categories instead of tags: https://developer.wordpress.org/reference/functions/wp_get_post_categories/ https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters your code could be re-written to: <?php $orig_post = $post; global $post; $cats = get_the_category($post->ID); if ($cats) { $cat_ids = array(); foreach($cats as $individual_cat) $cat_ids[] = $individual_cat->term_id; $args=array( ‘category__in’ => $cat_ids, ‘post__not_in’ => array($post->ID), ‘posts_per_page’=>3, // Number of related posts to … Read more

only delete post within query / for each statement (front end)

You should pass in the id of the post you want to delete as an argument of the delete_post() function rather than relying on obtaining it via global $post within the function itself: <?php echo delete_post($section->ID); ?> Then in your delete_post() function you can use the passed-in argument like so: function delete_post($sectionid){ $deletepostlink= add_query_arg( ‘frontend’, … Read more

add_image_size for header_image

This may can help you add_theme_support( ‘post-thumbnails’, array( ‘post’ ,’promotions’, ‘services’, ‘counter’) ); set_post_thumbnail_size( 200, 200, true ); add_image_size( ‘slider-image’, true ); Image will resize according to your html code

Remove meta description on certain pages

You should be able to remove the existing description tag with the following code: remove_action( ‘wp_head’, ‘_wp_render_title_tag’, 1 ); Put the above snippet inside the same function you are using to conditionally add a new tag so there is always only a single description tag at a time.