New answers tagged

1

Did I set up that wp_ajax_nopriv_ hook wrong? No, you did not. But that hook is for logged-out or unregistered users only. For logged-in users, the hook is wp_ajax_<action>. So you just need to change the add_action('get_events' in your code to add_action('wp_ajax_get_events', and the error 400 would be gone: add_action('wp_ajax_get_events', '...


3

There is indeed an unwanted ; (semicolon) in your function (try to look at line 99 in the twentytwentyone-child/functions.php file) which likely is the cause to the syntax error. So just remove that ; and the error would be gone: function my_service_template_footer_data() { echo "<script type='application/ld+json'> { '@context': 'https://...


1

Yes. Look into Custom Fields, or use the excellent Advanced Custom Fields plugin as Rup mentioned


0

You are populating the $term variable with a multidimensional array, but type-and-value checking it (===) against a string. Second, you say terms are 'des_1' and 'des_1' (with underscore), but are checking for 'des-1' (with dash). wp_get_post_terms will return an array of term objects, so you should might be better of with has_term() for checking if the term ...


0

Of course there can be many reasons, but if you require ajax.php in functions.php above the hook with wp_enqueue_script( 'myJSScript' ...); - it will not work. wp_localize_script() Works only if the script has already been added. function theme_enqueue_ajax(){ //try to add wp_enqueue_script( 'myJSScript' ...); here wp_localize_script( 'myJSScript',...


1

Perhaps you could consider using WP REST API to get the posts with a XMLHttpRequest in javascript instead of trying to get php work on .html file(s). From the REST handbook, The WordPress REST API provides an interface for applications to interact with your WordPress site by sending and receiving data as JSON (JavaScript Object Notation) objects. And It ...


1

You're generating whitespace because of the blank line between the echo $end block and the endwnile, and because you're switching in and out of PHP which means everything between the ?> and <?php - i.e. all of the whitespace - will get echoed out. (HTML then merges the blank lines and spaces into a single space for display.) You can just do this a ...


1

1) Run php code in html files You can't run PHP in .html files because the server does not recognize that as a valid PHP extension unless you tell it to. To do this you need to create a .htaccess file in your root web directory and add this line to it: AddType application/x-httpd-php .htm .html This will tell Apache to process files with a .htm or .html ...


1

A late reply but I thought I would include a snippet that worked for me. Update $allowed_inner_blocks with your own "block_types" and place the following code inside the parent block template; <?php $allowed_inner_blocks = ['acf/logos']; ?> <InnerBlocks allowedBlocks="<?php echo esc_attr(wp_json_encode($allowed_inner_blocks)); ?>...


2

If your template file doesn't have the <?php tag at the top, you should add it. <?php /* Template Name: Exhibition - Pilgrims */ ...is how the very top of your template file should look. Your sample should read like this. <?php /* Template Name: Exhibition - Pilgrims */ get_header(); ?> <div class="container fadeIn ...


0

In addition to what the answer at Dec 31 '19 said, I think this answer combines multiple answers given on this site. But since this website likes reproduction instead of references, I'll give a possible solution - including to the question of today (1 hour ago, according to my current screen). function prefixed_redirect() { global $wp; if ( home_url( ...


0

The login form's button uses the name 'login', and the register form's button uses the name 'register'. Check to see if 'login' or 'register' is in $_POST to determine which form was submitted: if ( isset( $_POST['login'] ) ) { // Login form was submitted. } if ( isset( $_POST['register']) ) { // Registration form was submitted. }


0

Without knowing the structure, class names, ids etc. it would be impossible to give you an answer that would help. But lets say that the structure is ul>li*6 <ul> <li>...</li> <li>...</li> <li>...</li> <li>...</li> <li>...</li> <li>...</li> </ul> ...


0

Implementing this functionality is not a difficult task, but it requires some work. I am going to help you out with a guideline of what I would do: You first need to think of a way to make a relationship between a user and the list of favorite posts. For example, you could have a user_meta field with key favorite_posts which contains an array of all the user ...


1

Your previous question, Possible to create a "variant" page template that only contains differences and is therefore resilient to updates of original (ie page.php)?, provided nicely more context to this question. As you Sally CJ noted in the comments you use theme_page_templates to add custom template to the template select list. To skip adding a ...


0

Assuming you are using custom query to fetch the latest posts from other categories. In that case, you don't need to hook into pre_get_posts as the category__not_in parameter can be passed directly into the query arguments. //Get the current category ID $catID = get_queried_object_id(); //Pass it to the Query arguments $args = array( //Your other ...


1

// hijack the download shortcode add_shortcode( 'dlm_gf_form', array( $this, 'shortcode_dlm_gf_form' ) ); This line just adds a shortcode from a class. I checked this plugin's class and they didn't provide any actions or filter. You can try to modify original code of this plugin for your purposes only. I don't see any other solution. I don't know what this ...


0

Get the ID using this: add_shortcode('wcal_abandoned_cart_id',function(){ return get_the_ID(); }); Use the shortcode [wcal_abandoned_cart_id]


0

You can pass the layout name as a GET parameter and then change the design based on that. So your URL should be something like this: http://domain.com/post-name?layout=layout-1 Now in your single.php file or whatever file that renders the template, you can do this check to show the different layouts: <?php // If the header is different two, you should ...


0

The shortcode callback function should always echo its output, not return it. Your code should be something like this: function wcal_abandoned_cart_id_shortcode_callback( $atts ) { $atts = shortcode_atts( array( 'post_id' => get_the_ID(), ), $atts, 'wcal_abandoned_cart_id' ); echo get_post_meta( $atts['post_id'], '...


0

You can set this in wp-config.php if you are facing redirect issues after migration. define( 'WP_SITEURL', 'http://example.com' ); define( 'WP_HOME', 'http://example.com' );


2

As @Buttered_Toest mentioned, this snippet works well. (This code goes to functions.php) function futy_widget_footer(){ ?> <script> window.Futy = { key: '0000000000' }; (function (e, t) { var n = e.createElement(t); n.async = true; n.src = 'https://v1.widget.futy.io/js/futy-widget.js'; var r = e.getElementsByTagName(t)[0]; r.parentNode....


1

This one will add php version at the bottom of 'at a glance' metabox, where goes wordpress version with active theme name. function update_right_now_text_callback($content){ $php_version = __('PHP version: ') . phpversion(); return $php_version . ' | ' . $content; } add_filter( 'update_right_now_text', 'update_right_now_text_callback' ); If you ...


1

If I understand it correctly, you can use a recursive function which loops through inner blocks to find the specific block. Example: /* Sample usage, assuming $post is defined properly: $blocks = parse_blocks( $post->post_content ); wpse_387661( $blocks ); */ function wpse_387661( $blocks ) { foreach ( $blocks as $block ) { if ( ! ...


0

The jQuery Migrate Helper fixed it. I’ll troubleshoot which plugin is causing the issue later.


2

I slightly modified your code and tested on my Wordpress installation. If you using a filter, like 'the_content', which recieves a content as an argument, you must also return this content back. Here is working version of your function with comments. //this filter recieves $content, which you should always return, //otherwise you will not see the content ...


-1

check this Code <?php get_header(); ?> <div aria-label="share article" class="front-page-div"> <div class="posts"> <?php if( have_posts() ) : ?> <?php while( have_posts() ) : the_post(); ?> <div aria-label="post" <?php ...


2

Yes, there is a filter you can use — all_plugins: apply_filters( 'all_plugins', array $all_plugins ) Filters the full array of plugins to list in the Plugins list table. And here's an example which changes the description of the Akismet plugin: add_filter( 'all_plugins', 'my_all_plugins' ); function my_all_plugins( $all_plugins ) { // the & means ...


-1

It is possible by opening plugin directory , in there find file name plugin-name.php , open it with editor and you should see : /** * Plugin Name: Your Plugin * Plugin URI: Plugin Uri (url ) * Description: Your custom description. * Version: 1.0.1 * Author: Your Name * Author URI: Your Site * License: GPL2+ * Text Domain: translate-...


1

Let's discuss our options for validating URLs in WordPress starting with the obvious ones. filter_var() with the FILTER_VALIDATE_URL filter in PHP doesn't work for internationalized domain names containing non-ASCII characters such as http://스타벅스코리아.com. It also has some other issues, as discussed by David Müller, like accepting http://example.com/">...


0

First, create a page from WordPress Admin called "About Us". Then choose the page template from the right sidebar of the "About Us" page under "Page Attributes" section. Then use the following code in any of your template files where you want to create a link to "About Us" page. <?php echo get_site_url(); ?>/...


1

Perhaps you could create a private utility taxonomy bookmarks, where each term would correspond to a user. When ever a user is created a new term would be added to the utility taxonomy. As the user bookmarks or removes one's bookmark from a post, your code would attach or detach the user equivalent term from the post. The user ID could be saved as the term ...


0

One option is to use PHP function empty() and the AND / && operator to build your if check to be certain that all of the required parameters are present. if ( ! empty( $type_search ) && ! empty( $area_search ) && ! empty( $prezzo_search ) && ) { // your ocde } P.s. type and area could be an excellent ...


0

A simple google search led me to this: You can't run PHP with javascript. JavaScript is a client side technology (runs in the users browser) and PHP is a server side technology (run on the server). If you want to do this you have to make an ajax request to a PHP script and have that return the results you are looking for.


0

Here I put orderby attributes as option values - date and title. <form method="GET"> <select name="orderby" id="orderby"> <option value="date">Newest to Oldest</option> <option value="title">Alphabetical</option> <button type="submit">...


0

There's a few things to consider, like where you're putting this... ...you didn't specify so here's how it would work in a custom post-type: First you'd have to add the metabox and the inputs to upload the file, then make sure that everything gets saved... <?php function add_your_custom_posttype_metaboxes() { //you have to set the above function as ...


1

I believe that your syntax is wrong in the variables you set up in your foreach loop. Because you're referencing an object and not an array, you need to use this format: $author_ID = $value->ID and... $value->display_name We also discovered that the foreach loop isn't necessary, so I'm removing it from the answer. The other issue is how you're ...


1

get_the_post_thumbnail function returns the post thumbnail image tag as a string. Use get_the_post_thumbnail_url function instead to get url. $url = get_the_post_thumbnail_url($pid, 'full');


0

I don't fully understand, but: function lw_search_filter_pages ( $query ) { // ... } if ( is_front_page () || is_home () ) {} else { add_filter ( 'pre_get_posts', 'lw_search_filter_pages' ); } Another: function lw_search_filter_pages ( $query ) { // ... } // https://yoursite.tld/blog $uri = $_SERVER [ '...


0

I'm just going on your answer code, try this... Below function returns same image data as used in native astra function. See source astra_replace_header_logo function // function for astra_replace_header_logo filter function fdx_astra_replace_header_logo() { // get your logo nav image id (defining 3rd param as false to return int id) $...


1

According to the documentation, you would have to use post_parent => 0 So your code would look like this: <div class="owl-carousel owl-theme"> <?php $c = 0; $q2 = new WP_Query( array( 'post_type' => array( 'post', 'book' ), 'post_status' => 'publish', 'post_parent' => 0, //add this ...


0

This code is my answer: <a href="<?php echo get_author_posts_url( get_the_author_meta('ID'), get_the_author_meta( 'user_nicename' ) ); ?>" class="m-article-author"> <?php $author_bio_avatar_size = apply_filters( 'tierisch_wohnen_author_bio_avatar_size', 49 )...


1

It depends on, where you are calling these functions. That is the point, where you enter the var into the function. First, remove the global $post from your functions.php! It makes no sense there! In the functions.php you declare the functions, not call them! I assume, you call your function in some template. So the functions.php should look like this: ...


1

Try to use wp_dropdown_pages instead of wp_list_pages . This function does almost the same, but returns a dropdown, instead of list items. (do not need to echo select opening and closing tags separately) if ( $post->post_parent ) { $children = wp_dropdown_pages( array( 'name' => 'your-name' // paste field name here 'child_of' ...


0

Seems like you need to change your action to publish_post. publish_post only fires when a post is published. The callback function will only receive only one argument, the post id, with it you can do all your needed checks and update the meta as needed. By the way, update post meta doesn't play well with ACF in the initial update. If meta field was empty it ...


0

This did the trick. Ymd was the correct date format. To get posts to show where no value had been added I just needed to refer to the CPT with no value and set it to NOT EXISTS. $meta_query = [ 'relation' => 'OR', [ 'key' => 'vacancy_end_date', 'value' => date('Ymd'), ...


0

How about extending the if statement to include the pages you require? Your code would look something like this: <?php if( is_front_page() ) { ?> <div class="bloc-header-home"> <span class="decouvrez">Découvrez</span> <h1>La chasse en licence</h1> <span ...


0

Ok guys, I found a first solution to my problem BUT now I have to fix an other one... here is what I started to do : <?php } elseif ( is_home() ) { ?> <h1>Actualités</h1> <?php } else { ?> <!-- TEST WITHOUT <h1><?php the_title(); ?></h1>--> <h1><?php single_cat_title(); ?></h1> <?php } ...


1

Ok, now it’s time to get your hands dirty. Open up your functions.php file located in wp-content/themes/your-theme-name/ and add this code in it: /** * Print the customer avatar in My Account page, after the welcome message */ function storefront_myaccount_customer_avatar() { $current_user = wp_get_current_user(); echo '<div class="...


-1

So you want to use sub categories?! Just add a new category "Bitcoin" with the parent category "Coins" and change your Settings > Permalinks to "Custom Structure" /%category%/%postname%/


Top 50 recent answers are included