Questions tagged [functions]

A function is a sequence of program instructions that perform a specific task. It is packaged as a unit that can be used wherever the according task should be performed.

Filter by
Sorted by
Tagged with
0 votes
1 answer
21 views

Custom editor color palette colors are not appearing in the editor

Below is the function to add my custom colors, the 'disable-custom-colors' is working properly, but the custom colors that I'm trying to add are not appearing in the editor. I have also tried clearing ...
user avatar
  • 17
0 votes
0 answers
30 views

Replace the_content with ACF Flexible Content via function

function replace_the_content($content) { global $post; // ACF post summary if (get_field('post_summary')) : $post_summary = '<h4> ' . get_field('post_summary') . '</h4>';...
user avatar
0 votes
1 answer
33 views

What is @Action in Wordpress?

I have found this code snippet on a plugin. /** * @Action(name="workforce_content_loop_before", priority=10) */ public static function show_breadcrumb() { echo do_shortcode( '[...
user avatar
0 votes
1 answer
23 views

Reject all malicious URL requests functions.php

this might not be the right place as it's a question about a function snippet that relates also to the server and log files. I have been trying to block access to my site from bad query attempts which ...
user avatar
  • 1
0 votes
0 answers
17 views

can't load .po file in functions.php

I get this warning Notice: Undefined variable: pofiles in /var/www/html/wp-content/themes/themename/functions.php on line 237 Warning: Invalid argument supplied for foreach() in /var/www/html/wp-...
user avatar
0 votes
0 answers
11 views

Add custom taxonomy using JS in post editor

Very Excited - First Post to SE! I am creating a wordpress app that uses Javascript to call some JSON data and brings it back into the editor. All of that is working great. I can console the data and ...
user avatar
0 votes
1 answer
11 views

Use a filter for wp_robots to block CPT/feed/

We have a CPT (with base slug templates) that somehow included in every single post's head a link to /templates/post/feed/. I've removed this link to the feed from the head, but want to block robots ...
user avatar
  • 1,760
0 votes
1 answer
14 views

How to divide Subcategories into pages of parent category wordpress

suppose I have sturucture like this: Justin Bieber > Albums > Justice when I visit on https://example.com/category/justin-bieber/albums/ It is showing all albums of Justin Bieber category. but ...
user avatar
0 votes
0 answers
23 views

How to assign page id with array in page_scheduled_event

How to assign multiple unique page ids with the below code - i have tried 'ID' => array('ID1, ID2, ID3), but not worked. add_action( 'page_scheduled_event', 'publishhome' ); function publishhome() {...
user avatar
0 votes
0 answers
10 views

How to keep plugin (media-sync) running even the tab is closed?

WP site is install with this plugin https://wordpress.org/plugins/media-sync/ It scans the upload directory for media files, then imports them into Media Libary. it works as expected when the tab is ...
user avatar
0 votes
0 answers
9 views

WordPress: Highlight search result exact matches

found this neat code to highlight search terms. My problem with the code is that it does not prioritize exact matches and it highlights words within other words. So searching for "in my hometown&...
user avatar
0 votes
0 answers
11 views

Custom image sizes showing in Classic Editor only when upladed directly to post

I can't get custom image sizes to appear in Image details size selector unless the image is uploaded directly in the post. If you choose an image from the Media library only default image sizes are ...
user avatar
  • 1
0 votes
2 answers
15 views

Custom Post Type Dashboard Tab not displaying any posts

I created a custom post: /*= Add Custom Post Type: Board Members /****************************************************/ add_action( 'init', 'create_board_posttype' ); function create_board_posttype() ...
user avatar
0 votes
0 answers
12 views

Trigger email alert if file downloaded

I've found this solution which triggers an email alert when an article is viewed, but wondered if a similar technique is possible for when a specific file is downloaded? function article_email_alert() ...
user avatar
  • 1,913
0 votes
2 answers
26 views

Completely Disable Wordpress RSS Feeds

There are loads of articles out there on how to completely disable Wordpress RSS feeds, my configuration (functions.php) is: function disable_feed() { wp_die( 'You Died' , 200 ); } add_action('...
user avatar
0 votes
0 answers
40 views

How to display conditional menus with Twenty-twenty two theme?

With earlier versions of default Wordpress themes I was able to display an alternative main menu depending on the category of the given page or post, using this filter in my functions.php: ( In this ...
user avatar
  • 217
0 votes
1 answer
18 views

Default click "I have read and agree to the website terms and conditions"

On WordPress checkout page, I want to make the "I have read and agree to the website terms and conditions" default clicked. Users can unclick the check icon. Is there any code available?
user avatar
0 votes
0 answers
20 views

Need help for some PHP code

I've already set all the fields in my theme settings but I want that carousel-items class repeats whenever I add slides to it, and [0] changes to [1],[2],... <div class="carousel-items"&...
user avatar
0 votes
0 answers
17 views

Load CSS before Theme CSS

I have a stylesheet I want to load first in the head before other plugins load css or theme css. For some reason priority is not working for me. Any idea how I can achieve this? I need to use ...
user avatar
  • 1
0 votes
0 answers
25 views

"pre_get_posts" orderby custom date field in different format?

I can set the query just fine for posts that have the date stored in the database in Y-m-d format, but I have a custom post type where dates are stored as n/j/Y (month/day/year), and would like to ...
user avatar
  • 279
0 votes
1 answer
16 views

WP function won't work on 404 template page

I made a custom template of error 404 page. In my header.php i use the_time() function to display current date. There is some problem with 404 page because the_time() function won't work, not return ...
user avatar
  • 145
0 votes
0 answers
17 views

WP-Bakery - Add custom colors to buttons with template colors

I'd like to add custom colors to the wp-bakery-front editor. Adding all the colors works but I just want to add the color of the current template. My function.php in the theme has the folowing ...
user avatar
  • 1
0 votes
0 answers
21 views

How to use wp_enqueue_script properly?

I'm trying to load mine scripts, but it doesn't work properly. function theme_enqueue_assets() { wp_enqueue_script('load_more', get_stylesheet_directory_uri() . '/assets/js/load_more.js', array('...
user avatar
0 votes
1 answer
35 views

Add custom text automatically on each post

Suppose I have a post and it's the first paragraph is: "This a Pen. The color is red." I want to add a custom text like "2022" after "Pen" on first sentence, at the end ...
user avatar
0 votes
1 answer
25 views

Custom Logo Link WordPress

I am trying to change the logo link of my wordpress website. But I am unable to achieve it. I am using child theme and using the code. function crunchify_custom_logo_url ( $crunchify_logo_html ) { ...
user avatar
0 votes
1 answer
15 views

How to hide content on mobile in the functions.php file - woocommerce

I have inserted an image onto my woo-commerce single product page using the below hook and code written into my functions.php file: add_action('woocommerce_after_single_product_summary', ...
user avatar
  • 1
1 vote
0 answers
31 views

Getting different functions data while using while loop in wordpress

I have added this code in the function.php file but when I use while loop in any other files this function is getting triggered. <?php add_action('loop_start', 'userlogin'); function userlogin() { ...
user avatar
  • 9
0 votes
0 answers
6 views

how to achieve this permalink abc.com/CPTName/CustomPostTypeCategorySlug/categoryname

I have created a cpt named blog. Registered taxonomy for blog as blog_category. I have a taxonomy-blog_category.php for displaying all categories of blog. When i click on a category the url i get is: ...
user avatar
  • 101
0 votes
0 answers
108 views

Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given

My WordPress site is using a custom theme written by a third-party. I am getting the white screen error on my pages saying There has been a critical error on this website. In attempt to diagnose the ...
user avatar
  • 101
0 votes
0 answers
8 views

I need to create "View Profile" and "Edit Profile" links by incorporating the Post Title/ID, but can't seem to manage it

I'm currently building a new site, using a front-end user form for members to go in and edit their own details, with an Administration-only front-end dashboard. Using plugin buttons I've already ...
user avatar
0 votes
0 answers
33 views

Can/should we delete wordpress cron jobs with no action?

I find myself during a website creation where I try several plugins and delete them afterwards. However, some plugins do not clean their cronjobs and are left to be executed with no action. My ...
user avatar
0 votes
0 answers
11 views

Woocommerce Default sorting product by product type

I have an issue, I want to order products loop by product type. I want the product group to appear first then followed by a simple product. I have code to order by date but don't know how to sort by ...
user avatar
0 votes
0 answers
15 views

Adding an "Upgrade Subscription" button to an Elementor page

I'm working on a website with Woocommerce Subscriptions and Elementor Pro. What I'm only trying to achieve is to add an "Upgrade Subscription" button to one of the pages. Someone has already ...
user avatar
1 vote
0 answers
17 views

How can I remove a function that has been added to wordpress with add_filter?

to begin with I am trying to modify a wordpress plugin. I have created a function named fuxia_is_the_best. Then I add this function to the sanitize_title filter, with the use of this code: add_filter('...
user avatar
0 votes
0 answers
12 views

Displaying registered sidebar after post content

I registered a new sidebar I'm trying to display after post content. I cannot simply output the sidebar somewhere in theme files, because the exact place I want it to display is not definied. I came ...
user avatar
0 votes
1 answer
14 views

Hide Author By-Line if After Certain Date

I'm trying to use functions.php to hide the by-line on posts after a certain date. I'm using the following code but it isn't working. I think it's due to not properly grabbing the post date. How do I ...
user avatar
0 votes
1 answer
31 views

Set Taxonomy based on post status

I am setting a taxonomy based on the post_status. It works as needed except I want to allow the taxonomy to be overridden if a particular taxonomy is selected. Here is the code function ...
user avatar
  • 95
1 vote
1 answer
97 views

Change the slug of a particular page every x hours

Is it possible to rewrite the slug of a particular page (e.g. Page-ID 123) with a wordpress function? I found this somewhere but It doesnt work and I am also looking to simplify it as I just want to ...
user avatar
  • 688
0 votes
0 answers
30 views

This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise

global $user_id; global $wpdb; if(is_user_logged_in()){ header("Location:https://www.recovermenow.co.uk"); } if(!$user_id){ if($_POST){ $...
user avatar
1 vote
1 answer
74 views

How can I recompile js file in dist folder?

I'm working on a project that loads a minified js file from my theme into a page <script type='text/javascript' src='http://localhost/mysite/wp-content/themes/mytheme-2021/dist/app.js?ver=5.9' id='...
user avatar
  • 111
0 votes
0 answers
28 views

Get webpack to work on child theme

I have previously created a child theme for the purpose of customizing some pages and it works fine, but now I'm facing some issues overriding the app.js file from my main theme. I'm following the ...
user avatar
  • 111
0 votes
0 answers
31 views

Using One Function To Create Two Different Shortcodes

To populate a player rollcall, an extensive query pulls data from tables in my external MySQL database. Part of this also extracts the player(s) who a) made the most appearances and b) scored the most ...
user avatar
0 votes
0 answers
23 views

How to convert Currency from USD to other IP Based currency in Php function

I am trying to implement a feature on Paid Membership Pro Subscription plans that can automatically change the plan currency to user's IP Based local currency and price can also be converted ...
user avatar
1 vote
0 answers
23 views

Set URL link to featured image of custom post type

I am storing data from an API in a custom post type made up with Advanced Custom Field. The API returns image urls, where each is given a text field in Advanced Custom Field. I'd like to set a ...
user avatar
0 votes
1 answer
13 views

Database entry removed on browser refresh, Ajax PHP jQuery

I have a form that updates columns in a database table on submit of a form via ajax. Everything works great, the database table columns get the information however once the browser is refreshed the ...
user avatar
0 votes
1 answer
28 views

Custom blog post summary on blog index page

Is it possible to have a custom function to truncate the contents of a defined DIV on a blog post page to use as the summary on the blog index page. So rather than using $the_content or $the_excerpt - ...
user avatar
  • 1
1 vote
1 answer
15 views

How to rewrite the custom url in wordpress?

I have tried to rewrite the url from http://example.com/club/?state=AL to http://example.com/club/AL Added query vars and rewrite url in functions.php add_filter('query_vars', 'my_query_vars', 10, 1); ...
user avatar
  • 11
1 vote
1 answer
30 views

Enqueue scripts not working with if is page conditional tag in functions.php

Is this even the correct way of including scripts on a specific page? function insert_mapsvg_scripts() { wp_enqueue_style( 'mapsvg_css', site_url('/mapsvg/css/mapsvg.css') ); wp_enqueue_style( '...
user avatar
  • 111
0 votes
0 answers
14 views

What is the best way to set the post category (Custom Post Type) automatically based on the one of the tags assigned to the post?

I have an automated workflow where I use a plugin in Adobe Lightroom Classic (LrC) to publish a collection of photos to my Wordpress site. This workflow automatically creates a project post (Custom ...
user avatar
0 votes
0 answers
19 views

Custom Form / Search with Custom Post Type Data

I'm trying to build a site that will allow people to check their status of vehicle registrations. I'll be using a CSV (without any Personal Identifiable Information) that is uploaded nightly (by ...
user avatar