Questions tagged [wordpress]

WordPress is a free and open source blogging tool and a content-management system (CMS) based on PHP and MySQL.

Filter by
Sorted by
Tagged with
3 votes
2 answers
146 views

Modify a WordPress loop to show posts of certain categories, based on user roles

I've got some code that works as intended, but I have a feeling that it's messy. This code is modifying a wordpress loop and the goal is to check the roles of the current user and show posts of ...
user avatar
  • 33
1 vote
2 answers
76 views

Optimize PHP code for Wordpress shortcode (Star-Rating)

I am using WP with the Avada theme and the built in Star Rating element as well as ACF Pro. Unfortunately I found out that the Star-Rating element adds a rating scheme to the footer of the website ...
user avatar
  • 11
0 votes
0 answers
23 views

Wordpress Custom Block that sources files from the theme images directory

The Goal Current PHP version 7.3.5 The block will have a function that sources a defined set of illustrations that are stored in {themeName}/images/illustrations. ...
user avatar
  • 401
0 votes
0 answers
36 views

Recreating WP Columns Block - Columns Container Only

I have been working on recreating the WP columns block using server-side rendered blocks. For the base creation of the block structure, I have used ...
user avatar
  • 401
3 votes
2 answers
51 views

Custom Block with ACF in WordPress

I'm learning and want to improve as much as possible. In doing so I have written this custom block that has an image on one side and an inner block on the other. It's using ACF to get the variables ...
user avatar
1 vote
1 answer
38 views

Instantiating classes in WordPress plugin

the last couple of weeks i have been working on my own WordPress plugin. I am trying to do a class based codebase. My plugin works correctly, but i don't really know if this is the correct way to ...
user avatar
2 votes
0 answers
28 views

Added custom woocommerce product page hook

I inserted this code snippet in the functions.php of my child theme, to create the woocommerce single product page in the hook woocommerce_after_single_variation of the custom icons in line centered ...
user avatar
  • 21
1 vote
1 answer
46 views

Building a pre-loader for performance gains in Wordpress

As the title, I am building a pre-loader for Wordpress running on PHP 7.3.5+ that will deliver performance boosts in loading, as well as metrics such as Google Page Speed. Now, this is something that ...
user avatar
  • 401
3 votes
3 answers
76 views

Order a table by column and get row number

In my database, I have table wp_postmeta, example: ...
user avatar
-1 votes
2 answers
85 views

Woocommerce order change status

This code can woocommerce order change status. But as you can see, this code is hard to read. How can I make it cleaner? ...
user avatar
0 votes
2 answers
68 views

Optimizing large WP Query [closed]

I have WP Query like this: ...
user avatar
  • 3
2 votes
0 answers
33 views

Copy the reply button to each comment thread in WordPress. Converted from jQuery to JavaScript

I converted an old Wordpress Plugin of mine from jQuery to plain JavaScript using a cheat sheet. I was very surprised that it seems to work right out of the box on my first try. ...
user avatar
  • 121
3 votes
1 answer
46 views

Query WordPress database, returning an array of rows

This is one of my first attempts at querying the WordPress database for data, and some my first PHP code ever, so please bear that in mind when commenting. It is supposed find data between two dates, ...
user avatar
  • 31
3 votes
1 answer
64 views

I need a better way to add css per each page on wordpress

I just started to use WordPress to start building a website, but as I need to use the get_header() function to retrieve the ...
user avatar
2 votes
0 answers
22 views

wordpress slow query shown in query monitor

I have a slow query on a wordpress site. How can I rewrite this to make it faster? I'm not having much luck. The query takes about 0.900 seconds I have both the query and the explain below, my goal is ...
user avatar
  • 21
3 votes
2 answers
117 views

Wordpress Ajax Custom Query - High CPU LOAD

I'm developing a fully AJAX community WP theme that comes with a lot of custom queries. Everything is fine, there is no bug but recently but I had a few clients that have a huge database and my theme ...
user avatar
1 vote
2 answers
222 views

Dynamic Accordion in WordPress

I used the Bootstrap v4.0.0 accordion to display my business services. Further, I created a custom post type "service" for my services (Each service is a post). To display my services ...
user avatar
  • 41
2 votes
1 answer
78 views

Efficiently use array values and variables in a WordPress template

Is it better to validate and put an array value into a variable at the top of a file or to check the array value directly right before output in the file? I work at a WordPress shop and we have a ...
user avatar
5 votes
1 answer
103 views

Wordpress single post content class customization with if-else function

I have the following code, which displays the content for my custom page template "landingpage.php" and for single posts. The site is based on Bootstrap 4. ...
user avatar
1 vote
2 answers
107 views

Shorten and optimize php custom code for wordpress page template and use shortcodes

I'm pretty new to php coding, but i know wordpress for a long time. Also experimenting with bootstrap. I created a new Page Template and modified it a bit. What I'm looking for is to optimize this php ...
user avatar
2 votes
2 answers
60 views

Function for iterating out an unordered list of custom taxonomy terms

I've created a function that generates an <ul> of my wordpress custom taxonomy terms, displaying ...
user avatar
  • 195
2 votes
1 answer
55 views

Display content if form field is filled - Do not display if field is empty

I am using the following code within the footer of my test site. I am using WordPress and Advanced Custom Fields The intention is: To display the HTML container ...
user avatar
  • 401
3 votes
1 answer
46 views

Performance of WordPress Plugin is currently very bad and needs to be improved

I have written the following Plugin, which adds fields to the Media/Attachment Entries and returns all information in one Shortcode. This solution works, however, is pretty slow the more entries ...
user avatar
4 votes
1 answer
28 views

Simple Bespoke WordPress Integration Plugin

I am in the process of setting up WordPress with WooCommerce, one of the requirements is a bit of integration that takes a person from another website directly to a specific product. I have set the ...
user avatar
2 votes
1 answer
144 views

Replace anchor tags and force create new tag with custom attributes

I'm just use the add_filter('the_content', function($content){}); for filtering anchor tags in a post. Basically, I want filter anchor tags to appropriate format. ...
user avatar
1 vote
1 answer
42 views

Improved the output of the related posts in WordPress

I made a simple code to improve the results for WordPress related posts area and it works fine , but because my experience in coding is low , my code is very long and i believe that there is a way to ...
user avatar
  • 43
3 votes
1 answer
57 views

WP/PHP getting API data and using hook

Below are the two things I'm trying to solve, logically. This is just a proof of concept; and I'm not implementing this on real data nor via full plugin at this time. Just looking at logic and syntax ...
user avatar
3 votes
0 answers
434 views

Product Filters wordpress plugin: implement single responsibility principle for elements classes

Plugin is a small editor that allows to create a filter such as a price slider, checkboxes of "brands", a drop-down of "seasons". An example of how plugin work can be seen on page: http://demo-...
user avatar
1 vote
0 answers
40 views

WordPress plugin to reveal coupons after several visits to a page

My file tree is here. It does not look good. I would appreciate any tips you have on improving code organization. My React mindset of breaking folders by component didn't carry over well into php/...
user avatar
  • 111
2 votes
1 answer
526 views

Prefixing prices of certain product categories with text in Woocommerce

I had the need to prefix the price for certain product categories on only the shop page (because the price can be higher depending on extras that the customer might want). These were my requirements ...
user avatar
  • 153
3 votes
1 answer
53 views

Filtering wordpress comments by votes

I have a website that, based on a user's comments, filters comments by "most liked first, most disliked first" etc... I have a custom table for comments scoring system and system working with +1 and -...
user avatar
0 votes
0 answers
36 views

WordPress hook to add URL-rewriting rules for articles with language variants

Please look at this working WordPress code: ...
user avatar
1 vote
0 answers
27 views

Custom WordPress SQL query to get posts and users using term_id

I have a WordPress site with multiple custom post types, that all share a common custom taxonomy. Users can also be tagged with terms from this taxonomy. After giving up on ...
user avatar
1 vote
0 answers
66 views

Proper image sizes in WordPress

I wanted to create a set of functions that would allow me to easily implement images for multiple screen resolutions in my custom page templates. WordPress offers some functionality for implementing ...
user avatar
  • 148
1 vote
0 answers
28 views

Simple cart update WordPress plugin

I created a plugin to update cart automatically on quantity change with some additional options. I want to focus only on the main plugin file, skipping uninstall.php and .js file which are entirely ...
user avatar
2 votes
0 answers
101 views

WordPress rest api basic auth with IP check

I'd like to use basic auth with the WordPress API, but restrict the capability to a single IP address. I've updated the existing code from here: https://github.com/WP-API/Basic-Auth accordingly. It ...
user avatar
  • 121
1 vote
2 answers
405 views

PHP subscription workflow

I've creating a working subscription workflow for my webpage, which heavily utilizes a set of functions I've created for this purpose. However, after doing some testing (functionality works fine), I'...
user avatar
  • 11
1 vote
1 answer
71 views

Feeding PHP variables to a number of HTML elements

The following code works fine, however, I'm trying to simplify it. I wrote it but I'm a beginner PHP coder. I can see that most probably the use of a function or class would be better... or anything ...
user avatar
  • 527
1 vote
0 answers
563 views

Load more and filtering - WordPress AJAX

In my WordPress theme I have built a function that uses Isotope Layout by Metafizzy to accomplish filtering and sorting. I have used a mix of AJAX and JQuery to accomplish this, however I feel the ...
user avatar
2 votes
0 answers
233 views

Generating two Woocommerce Order CSV files based off url query

I wrote this code about one year ago. I'm looking to refactor it to be solid SOLID and secure, as this is being generated off a custom endpoint. The script is to read parameters from a query and ...
user avatar
  • 183
2 votes
1 answer
103 views

Checking if a shipping method exists

I am trying to create a custom WordPress/WooCommerce function in PHP. I am a newbie and would really appreciate some feedback on my code and how to improve the code! Right now it feels like there is a ...
user avatar
  • 123
2 votes
0 answers
27 views

Create a new WordPress admin page, and add an admin table to it

I completed this WordPress coding task as part of an interview. I'm hoping someone can review my work and comment on everything, especially my general approach to the task, and the sanitization of ...
user avatar
  • 121
3 votes
3 answers
213 views

Check if a postcode is in a list

I'm looking for improvement / advice / reviews on how I can improve this code. I feel like there is a better way or more efficient way of doing this and I am over looking it. The Plugin I made is ...
user avatar
2 votes
0 answers
31 views

WordPress plugin for shipping calculation

I am writing a WordPress plugin that allows shipping calculation on the product page. Originally, shipping calculation is only available in the cart. To calculate shipping costs on product page, ...
user avatar
1 vote
0 answers
32 views

WordPress plugin development - plugin-name.php file and plugin files/folders structure

I am creating my first WP/WooCommerce plugin. I was following instructions from WordPress Codex during development, but I wanted to review it here, to make sure I am on the right path. First things I ...
user avatar
  • 111
1 vote
0 answers
45 views

WordPress plugin for listing users

I was given an opportunity to join a WordPress contractor/freelancer website and was asked to build a plugin that would list the wordpress users in the database, allow you to filter them based on ...
user avatar
0 votes
1 answer
135 views

Formatting fractions found in a given string to html fraction

I'm working on a site running woocommerce and wp where the user will add/has added a dimension attribute. The dimension string will take the following format originally: Ht: 30 1⁄2" W: 22 1⁄2" D: ...
user avatar
  • 148
5 votes
1 answer
574 views

JavaScript responsive menu (dropdown/dropup)

I have the following front-end code for a responsive navigation menu which I thought using in my WordPress website. Clicking the .burger element should cause ...
user avatar
3 votes
1 answer
116 views

Conditionally displaying a notice about free shipping in Woocommerce

I wrote PHP code to display a Woocommerce notice - "free shipping for $40 & under" only once on shop page and once on cart page, but also in cart should not be more than 40$. The code works, but ...
user avatar
1 vote
2 answers
50 views

chmod all .htaccess files under all website dirs under public_html dir

This is my code to chmod all .htaccess files under all website dirs under public_html dir. The reason I use this code is to make sure WordPress plugins won't "...
user avatar