Questions tagged [php]

For questions about the server-side programming language that the WordPress core, plugins and themes are written in. Questions about using PHP outside a WordPress context are off-topic but might be asked on Stack Overflow.

Filter by
Sorted by
Tagged with
1
vote
1answer
14 views

Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?

I currently have a Portfolio custom page in Wordpress, so far work as i want, but i have one problem. The problem is when i click one of the button slug then the body/output is not work like i want, ...
1
vote
0answers
23 views

How to programmatically add Gallery Block to Existing Post Content

I need to insert a set of images already in the media library to the end of the content of each new post. Instead of inserting the html directly is there a way to add a Gallery block by using the ...
0
votes
0answers
40 views

When I click for the redirect link it is showing the content of index.php instead of single_assignment_page.php

When I click on a link to redirect to 'single_assignment_page.php' it is not showing the content of this page but it is showing the content of 'index.php'. That's something I don't want but in the URL ...
0
votes
0answers
15 views

Ajax result show in console if is called outside function and not showing in array

In wordpress theme I must change custom functionality and use ajax, so I have dropdown and on change I grab selected option: JS $( ".select-class" ).change(function(e) { var ...
0
votes
0answers
21 views

Replace jQuery with PHP or CSS for Customized WordPress wp_nav_menu

Does anyone know how to build a custom wp_nav_menu layout without using jQuery? My current menu loads fine, but it causes the whole page to shift. jQuery adds CSS classes to items in the menu after it'...
0
votes
0answers
10 views

How to make a front end fields from metabox

I want to clarify that I am not a specialist, my query is how to insert a metabox in the front end, specifically I show you the image: I want to do this: But actually I have this: Those are the php ...
0
votes
0answers
19 views

How to define a variable and use it in shortcode?

I am new to wordpress development as well as php and html programming and I need some help with something. I would like to get the title of a bbPress topic and then store that in a variable. Then I ...
0
votes
0answers
13 views

Woocommerce add products to cart

Is there a way to add a product to woocommerce cart without passing the product ID? So I have a DB with products and I do not want to import these products to woocommerce products in backoffice. Can I ...
2
votes
2answers
28 views

enqueue hover function

I am trying to enqueue a hover function in my functios.php of my child theme, so that when hovering over a title, a div with a text will be visible. The code I am using is this: <?php add_action( '...
0
votes
1answer
34 views

Custom Shortcode with Dynamic Button

I am lost as to how to create a dynamic button shortcode. Depending on the post ID a specific application form is served in a popup by clicking on a button labeled 'Apply'. At the bottom of the page ...
0
votes
1answer
112 views

How to set up phpcs with WordPress coding standard with PHP8?

Trying to set up PHP_CodeSniffer with the WordPress Codings Standards. I'm running PHP v8.0.3 and phpcs v3.5.8. (in March 2021). WPCS is installed via git clone -b master https://github.com/WordPress/...
0
votes
1answer
31 views

<?php the_post_thumbnail_url('medium'); ?> not outputting medium size image URL

I am currently trying to output post thumbnail URL with its different image sizes; to use in ssrcset. My current code is: <img class="productimage lazyload" data-src="<?php ...
0
votes
1answer
26 views

Fixing Deprecated: get_the_author_lastname

i have a plugins with just a single php code <?php /* Plugin Name: COinS Metadata Exposer Plugin URI: http://www.zotero.org Description: Makes your blog readable by Zotero and other COinS ...
0
votes
2answers
105 views

Gutenberg block don't save rich text content

I could not get to work. When published the content the attribute innerContent didn't save. Here is what I tried. block.js // Import CSS. import './style.scss'; import './editor.scss'; const { __ } =...
0
votes
0answers
10 views

Limit the word count in the post title in footer for Wordpress

I would like if someone can help me to display the title with read more or ... from the footer of the website, Recent Posts area. Website: https://hygiero.ro/
0
votes
2answers
34 views

Wordpress query undefined offset in loop

I created a query with arguments see blow. On the page I see an error in a loop Notice undefined offset 1 Notice undefined offset 2 Notice undefined offset 3 and so on... $args = array ( '...
0
votes
2answers
39 views

Referencing Images in javascript to display on wordpress page

So sorry if this have been answered - but in that case, I surely do not know what to ask. Anyway, I have built an image slider which changes the image and the description of the image on click of a ...
0
votes
0answers
11 views

pretty permalink registration default wordpress page

Is possible to use permalink to redirect the user to the registration page?Also this one can be customized using an headless wordpress install passing the form fields using an ajax post request?My ...
0
votes
0answers
14 views

Select Image from Media Library and insert into page with responsive markup

I'm building a site for my friend which uses a custom theme and no page builder. The home page has 4 splash images, and to make things as simple as possible for him I'm trying to create some ...
1
vote
0answers
31 views

How to set up VS Code for WP plugin/theme development in 2021? [closed]

I'm trying to improve my WP theme and plugin development workflow. VS Code is my editor/IDE of choice and I'm pretty with it in general. However, setting up VS Code with debugging, formatting, linting ...
0
votes
0answers
15 views

Allowed memory size of 134217728 … wp-includes/wp-db.php on line 1989

While accessing WordPress dashboard> Fatal error: The allowed memory size of 134217728 bytes exhausted (tried to allocate 12288 bytes) in /home/paleobri/public_html/wp-includes/wp-db.php on line ...
0
votes
0answers
23 views

Display suffix according to VAT status

I want the price suffix to change within WooCommerce depending on what VAT status is selected. So for example when I show the prices excluding VAT the suffix should read 'excl VAT' and where the ...
0
votes
1answer
58 views

How to check if the current page is at a specified path in the URL?

I have a page marked as the Posts page that lists most recent blog posts. It is at path /blog. I want to know when the user is on this page so that I can display a list of categories of blog posts at ...
1
vote
1answer
19 views

How to prevent XSS alter custom global javascript object & methods in Wordpress

Im working on a project in Wordpress that enqueues multiple .js files where each file adds a new method to a global javascript object, this in order to make the desired methods available only if ...
0
votes
1answer
18 views

how to remove a query arguments from all site urls?

I use url query arguments to display messages ether errors or info messages for example i use https://www.example.com?error=myerrormessagegoeshere or https://www.example.com?success=...
0
votes
1answer
40 views

Most commented posts by time period (last 12h, last 24h and etc)

I have this code which works great. <?php $result = $wpdb->get_results("SELECT comment_count, ID, post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 25"); // ...
0
votes
2answers
43 views

Which is the correct way to conditionally enqueue a CSS file?

get_queried_object returns NULL inside a function hooked to wp_enqueue_scripts action hook when going to an nonexistent category URL on my website. If the category exists, the error is not shown and I ...
0
votes
1answer
23 views

What is an equivalent of single_cat_title for getting the slug of the category?

I searched for something like single_cat_slug but I did not find something relevant. All I don't know how to do it is to find the slug, not the name, of the currently opened category page. I do not ...
1
vote
1answer
43 views

Sanitizing, Validating and Escaping in WordPress (Plugin)

I am currently developing my first WordPress plugin. A few days ago I submitted it to WordPress for review. Unfortunately, the plugin was not (yet) published, because I still have to close some ...
0
votes
0answers
17 views

Confused. How to remove WP_Query $args from AJAX posts loop and make it work?

I am currently working on a custom theme project where I am trying to make AJAX load more function work for custom-post-type, 'product' I just made. I went through a tutorial on internet and got the ...
0
votes
0answers
7 views

How to set the featured image / page thumbnail from php template?

I added a template php to my Wordpress site, showing a basketball image from url, I'd like this to be the thumbnail of my website when sharing on social media My php template- <?php /* *...
0
votes
0answers
15 views

How to access theme template variables from page's code editor?

I created a new php template for my page, and choose it with Page attributes- Template. This php template has an $imageData variable which I want to load into my page with the code editor (instead of ...
0
votes
0answers
24 views

AJAX Load More Posts not working in my custom WordPress theme. Help!

I have been working on my custom theme since last week. I am trying to code kind of an eCommerce solution. Well, I registered custom-post-type called 'product' and was coding archive-product.php. I ...
0
votes
0answers
16 views

Unsure what to name my Post type Category Template

I previously was using the woocommerece product_cat on my taxonomy-product-cat.php page, But now Im making a separate post type called Productzs. So the annoying bit about this is the template needs ...
0
votes
1answer
34 views

How to use html inside a functions.php code?

I actually have a little problem while trying to use html inside a fuction code. It is something like this. /* AJAX for Posts */ function misha_loadmore_ajax_handler(){ $args = json_decode( ...
0
votes
0answers
18 views

get_the_terms only show last category term in Wordpress?

I'm using Elementor PRO and I'd like to edit the post badges to display not the first term [0], instead it should display the last term shown in the category display. For example I have posts inside ...
0
votes
0answers
20 views

Add user name in the URL like sub-folder

I want to add a username or any other dynamic string after the site URL like http://example.com/username-a/page-url http://example.com/username-b/page-url or it may be any string in the URL like ...
0
votes
1answer
36 views

Is it unsafe to put php in the /wp-content/uploads directory?

Pretty straight forward question, but I'll provide any clarifications needed. The reason I'm asking is this: I created a child theme that pulls in a custom-functions.php file. This allows devs to ...
0
votes
0answers
11 views

How do I add a BCC field to a WP_MAIL function on Wordpress [duplicate]

I need some help from someone. I managed to get this below code working on sending emails to a certain user role. However, when the emails sends it sends to all 200 people and they can all see each ...
0
votes
1answer
25 views

How to: Conditionally Enqueue JS and Stylesheets, for Custom Post Type (Single and Archive Templates)

I’ve created a plugin for my child theme, in which custom functions are stored. Additionally, within the plugin, I'm also enqueueing stylesheets and .js which control the output of two templates, for ...
0
votes
0answers
12 views

How to make AJAX Load More Posts on Scroll for custom theme and custom-post-type?

I am currently working on a project where I am coding a custom theme with custom-post-type called products. Now, I am coding archive-product.php and stuck at making an AJAX load more posts on scroll ...
0
votes
0answers
8 views

Using a search string in the URL for Wordpress when upgrading to PHP 7

I am managing a fairly old Wordpress Theme for a local art gallery. The theme has been heavily customised based on the clients requirments. Most of the content is delivered usng a search string in the ...
1
vote
0answers
11 views

Using meta_query to get date type values from post_meta table WordPress

General View I am creating a plugin which imports a csv file and using a shortcode i created a form that can search values from the uploaded csv file in sqlData base. Form have Three Input fields ...
0
votes
1answer
83 views

Divi change project category slug

How to change taxonomy urls in wordpress? Following along with this question and this one But can not get the desired outcome. The default is: example.com/project_category/%category%/ What I want is: ...
1
vote
0answers
149 views

wp search-replace on database returns PHP fatal error: Array and string offset access syntax with curly braces is no longer supported

So I need to setup a client website locally for improvements. I'm trying to search and replace any instances of the live site's name/url and replace it with a development one. When I run the command: ...
0
votes
1answer
19 views

Undefined offset: 0 in WordPress after latest version upgrade [closed]

My WordPress powered website always worked great, however after the latest upgrade to 5.6.2 and 5.7 I have a major issue that actually breaks an important part of the website, I have seen to go ...
1
vote
2answers
26 views

Get different images for mobile and desktop with php, advanced custom fields without using js and ajax

I hope everyone is well! I am looking for a possibility to load different galleries, background images etc for the phone and desktop. For example, I set my hero background image like this: <...
0
votes
0answers
20 views

Wordpress loading progess - wp-blog-header.php

I have a doubt about wordpress loading process. In maintenance mode will the wp-blog-header.php file used to display the admin dashboard?
0
votes
1answer
39 views

Content-Security-Policy Headers are there and showing the correct settings, but still getting a refused connection

So I'm putting a plugin together that will allow me to connect multiple client sites with an online service. I can get the service vendors snippet to load, but once you interact with it, that's where ...
0
votes
0answers
11 views

Updating options of a widget with own tool

I am writing a tool to update the options of a self-created widget outside the backend "Appearance - Widgets" page. These are simple yes/no options in the widget. It seems to work as I am ...