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

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.

Redirect to a different page through registration, depending on page

Changing the function to the following works, as it checks to see if the form was submitted from the correct page: function my_foo_registration_redirect( $redirect_to) { if ($_SERVER[‘HTTP_REFERER’] !== get_the_permalink(1693)) { return $redirect_to; } $redirect_to = ‘/videoguide-startpakke’; return $redirect_to; } Thanks a lot for the super helpful comments! EDIT: Here’s a slightly more polished solution function … Read more

how to delete 30 day old data using PHP [closed]

You’re adding an extra wp_ prefix to your table and your using a timestamp instead of a MYSQL datetime. Below is how WP suggests you use $wpdb->query to delete rows, taken from the codex. EDITED global $wpdb; $wpdb->query( “DELETE FROM ” . $wpdb->prefix . “userinfo WHERE timeall < DATE_SUB(CURDATE(),INTERVAL 30 DAY)” ); $wpdb->prefix adds the … Read more

Ajax not working es expected (Returns 0)

Please try this: Add the following in your theme’s functions.php add_action( ‘init’, ‘tnc_aj_scripts’ ); function tnc_aj_scripts() { wp_register_script( “ajax_anmeldung_script”, get_template_directory_uri(). ‘/my-ajax.js’, array(‘jquery’), ‘1.0’, true); wp_localize_script( ‘ajax_anmeldung_script’, ‘mYAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ))); wp_enqueue_script( ‘jquery’ ); wp_enqueue_script( ‘ajax_anmeldung_script’ ); } add_action(“wp_ajax_ajax_anmeldung”, “ajax_anmeldung”); add_action(“wp_ajax_nopriv_ajax_anmeldung”, “ajax_anmeldung”); function ajax_anmeldung() { $result[‘one’] = ‘Hey’; $result = json_encode($result); echo $result; … Read more