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
3
votes
2answers
2k views

How to remove a metabox from menu editor page?

I am not sure if it is much different for any page but I am wondering how to remove a metabox from the appearance>menu page without having to go into the wordpress core files and remove it. Is there ...
3
votes
1answer
1k views

WordPress Shortcode and Dynamic CSS

I have a question I would like to ask to the WordPress developers, Usually when creating a shortcode that need to generate custom css how do you proceed? For example a simple button shortcode with ...
3
votes
1answer
4k views

urlencoding of the_title() doesn't work?

hey guys, <?php urlencode(the_title()); ?>doesn't take effect. this is my entrie line of code: <li><a href="mailto:?subject=<?php urlencode(the_title()); ?>&amp;body=<?...
3
votes
1answer
825 views

Can i check if user is doing any ajax request?

I make a custom user meta and its name is last_activity. I use this meta to get the date of user last activity and I updated the meta each time user open a page using WordPress wp_head action. My ...
2
votes
2answers
3k views

If in parent category

I have this structure Category > Subcategory > Post I´m trying to display some content if the user it´s on a specific category, or in it´s subcategory or post. I´m using this code but it only works ...
2
votes
2answers
2k views

How can I access the “description” of a menu item?

Where you can add your menu in under appearance > menus, I have descriptions in. In my page, I want to be able to echo out that description. Not in the menu, but in my page. How can I access this ...
2
votes
3answers
7k views

Run shortcode at certain resolution

I've gone a roundabout way of trying to ask a question about this here: Loading shortcode with ajax but figured it might be worth asking the fundamental question of what I am trying to do without ...
2
votes
1answer
2k views

Multi step form, custom plugin

I have built a working multi-page contact form that has Zoho CRM & Slack integration. What I want to do is when a user goes to our contact page, they will see the first half of the form (step1....
2
votes
1answer
2k views

How to Remove Parents Category Permalink from Posts

Simply speaking i want to do something like this. http://example.com/parent-category/child-category/post-name change into http://example.com/child-category/post-name I found some solutions, but ...
2
votes
1answer
67 views

Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?

So this may be a very noob question, but I believe if I can get the answer to this I can clean up code and speed things up significantly. I build projects using Woocommerce quite a lot, and in doing ...
2
votes
1answer
2k views

Bulk Image upload and one image for each post?

I have around 3000 photos, want to upload on WordPress. Is there any way to bulk upload all the photos as one image for each post ?
2
votes
2answers
1k views

Display certain amount of posts on taxonomy archive page

I have a taxonomy archive page where I display everything under the term 'techno' I want to be able to limit this to 20 posts to a page until it paginates. At the moment it displays 10 on one page and ...
2
votes
2answers
5k views

how to create and show sessions in word press?

I am new to word press but know all the required PHP skills. I am using a form to create session in one page and then accessing those sessions in another page. I have done this already without word ...
2
votes
2answers
525 views

Change dns-prefetch to preconnect with correct protocol

I have this function in my functions.php file: function dns_prefetch_to_preconnect( $urls, $relation_type ) { if ( 'dns-prefetch' === $relation_type ) { $urls = []; } if ( '...
2
votes
2answers
8k views

How to turn off redirection from 'domain.com/login' to 'domain.com/wp-login.php'

I want to install something different than wordpress under 'mydomain.com/login', but WordPress automatically redirecting this link '/login' to '/wp-login.php'. Where can I turn off this redirection?
2
votes
2answers
6k views

Replacing a specific menu item

So, I understand how to target a specific menu using the following to add a custom code. <?php wp_nav_menu( array( 'menu' => 'Project Nav', // do not fall back to first non-empty menu '...
2
votes
3answers
10k views

Plugin.php: PHP Notice: Undefined offset: 0 in

I moved a WordPress site from one domain to another and there were a lot of white spaces that needed to be removed. The only problem that is left are the following errors: PHP Notice: Undefined ...
2
votes
1answer
862 views

WordPress Customizer: How can you have multiple active callbacks on one control?

I have the following two Customizer controls that displays a checkbox for showing/hiding content. Each checkbox is followed by an active_callback that shows/hides the corresponding controls when the ...
2
votes
1answer
3k views

Specified file failed upload test. wp_upload_handle

So I managed to write a peice of code that allows me to upload a zip file, im not even sure where it gets uploaded too, and I am doing it on my localhost with apache in control (www-data). the code is ...
2
votes
2answers
2k views

Correct use of curly braces vs alternative synax

In most themes I've looked at and WordPress core, I'm seeing the use of endwhile and endif. Is there a good reason why WordPress uses these instead of curly braces for block statements?
2
votes
3answers
1k views

“wp_enqueue_style();” don't load new edited style

First, sorry my english. I am using Local by flywheel to manager my site files and my wordpress version is 4.9.4. Here is the problem, When I use wp_enqueue_style('wharever', get_stylesheet_uri()); ...
2
votes
1answer
4k views

How can update custom meta for all posts

How can update custom meta (likes) for all posts that have this meta? If i used something like this: update_post_meta( $post_id, "likes", 1 ); it's required to add the post id that I need to update ...
2
votes
1answer
2k views

How can I run a .php file located in my site's root folder?

I am trying to convert some data from custom post types into custom tables in my Wordpress database. I have written a PHP program to do this. It requires that Wordpress be loaded so I can use some of ...
2
votes
2answers
2k views

if has theme mod

Does someone know how to write the next line in wordpress PHP, because i'm not that great with PHP. If_theme_mode has content echo { my content } else { other content }; thnx
2
votes
2answers
7k views

How do I make wordpress comment fields required?

Here is my form: <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" class="validate"> <?php if($user_ID) : ?> <?php ...
2
votes
2answers
2k views

Saving metabox repeatable fields

This is a code that I'm adapting from https://gist.github.com/2057532. The problem is that I'm not being able to save the content from the new fields that I created. I had checked the other questions ...
2
votes
2answers
1k views

Activate different theme for temporary preview

I wanted that when i access my site with specific parameter, my site used a different theme at that moment (only temporarily, to show only to me as a preview). I want it for test purposes. Is there ...
2
votes
1answer
11k views

Insert plugin content before body end

How do I make plugin's content appear in a place I want? For example let's say I have a plugin that output's a paragraph: echo "<p>foo<p>" If I do this it will appear on a page outside ...
2
votes
3answers
2k views

Allowed memory size of 268435456 bytes exhausted (tried to allocate 64 bytes)?

I am getting this error. I have increased the memory limit upto 512M. I have more than 4000 posts with so many data. Website is working fine. But when I am trying to access the custom post type page ...
2
votes
1answer
126 views

PHP Script within wordpress theme

I have a php script that I'd like to utilize within my wordpress theme. I'd like to restrict access to the page based on users belonging to particular groups so it's important to keep it within ...
2
votes
3answers
6k views

How to Create a Directory in a Plugin Folder?

I am creating a plugin in WordPress Version 3.4.2. When the administrator submits a form, a new folder is created inside my plugin directory and a file saved in this new folder. But it gives me the ...
1
vote
1answer
45 views

Targeting single page with JS

I created a JS and PHP code to query a database and display matching rows on a page. It was messing up other pages on WP, so I wanted to know how to target a single page so the JS doesn't run on ...
1
vote
1answer
4k views

Add footer.php to Wordpress child theme

So I am using the theme of 'Mesmerize' I have created a child theme but want to change some of the footer php within the child them so when there is a theme update the changes done reverse. This is ...
1
vote
4answers
6k views

removing <li> tags from wp_list_pages() using PHP

as the title states, I am trying to remove the <li></li> tags from the list that gets generated with wp_list_pages(). My thinking is to somehow run a for/foreach loop through the menu ...
1
vote
2answers
2k views

List authors with posts in a category

I'm trying to create a custom widget to display contributing authors for the current category being viewed on a WordPress site. I have the following PHP code: <?php if (is_category()) { ?> // ...
1
vote
0answers
25 views

Limit Authors to their Own Posts on front-end excluding admins

I'm trying to limit custom post type "Projects" only to post authors excluding the admins. I'm trying the following code: function project_view_for_only_author($query) { global $current_user; ...
1
vote
1answer
125 views

How to save Clicks of a download link button while it doesn't matter if we refresh the page or again login/logout

I am working on a wordpress site and i am little stuck into one situation , what i want is that:_ I have one resume page, which shows resume posts from wp_postmeta table and each post have a downlaod ...
1
vote
1answer
690 views

Retrieving all data from repeater fields

I have a custom field in WP called what_we_do_textarea_two. what_we_do_textarea_two is a simple repeater field which allows you to add another item to a list. what_we_do_textarea_two has a subfield ...
1
vote
1answer
110 views

Changing the HTML Of the content

<?php the_content(); ?> When we use the above the content is published like this → <p>Content is published</p> If I want to later this HTML and instead of <p></p> I ...
1
vote
1answer
4k views

Automatically check the option “Enable stock management at product level” on product creation

We have a peculiar WooCommerce setup where each product is only sold once. So we set each product to have 1 stock on creation automatically. Using stock management feature in WooCommerce requires an ...
1
vote
1answer
3k views

$wp_filesystem returns NULL. What are the dependencies?

I need to obtain a reference to the $wp_filesystem object. In the test below, the var_dump($wp_filesystem) returns NULL. What additional files are required in order to properly set up $wp_filesystem? ...
1
vote
1answer
605 views

Thumb rating for wordpress - top user

I am currently using gd star rating (thumb rating) to rate posts (articles - no rating on comments). What I really want to do is show a table of the top 5 users and their number of votes based on the ...
1
vote
1answer
313 views

How do I edit the php/html for a particular post?

I am new to Wordpress but I am comfortable coding in html/php and want to create custom forms on some of my posts. My site is currently running on localhost. I feel very silly because I have been ...
1
vote
1answer
241 views

Sort posts from multiple sites by date

I have a WordPress Multisite installation where I need to get all the posts into one feed on the main site. I have tried a using a SQL query, but that stopped me from accessing a lot of needed data. ...
1
vote
2answers
667 views

Getting a fatal error while updating

Every time i tried to update WordPress ,i faced this error: Fatal error: Maximum execution time of 120 seconds exceeded in G:\wamp\www\wordpress\wp-includes\Requests\Transport\fsockopen.php on ...
1
vote
1answer
3k views

How can I call a row of user specific data from a custom table added to the WP Database

I have setup my WordPress site, customized the Theme as well as a couple plugins, I have also added a custom Table to the WordPress database that will contain user specific information. I am wanting ...
1
vote
3answers
2k views

get_the_content if it contains multiple lines it results in SyntaxError

I use get_the_content to pass to a javascript variable, and then back to another PHP function. This works great, but there is an issue when using get_the_content. If the post contains only one line (...
1
vote
1answer
314 views

How to upload imagick resource to media in wordpress

$filePath = wp_get_attachment_url( $id ); $tempfilename = explode("/", $filePath); $temppdffile = end($tempfilename); $cuurentPath = plugin_dir_path( __FILE__ ).$temppdffile; $im = new Imagick(); $im-&...
1
vote
0answers
283 views

Authenticating to Wordpress, using my own authentication two-factor system

This is basically the same request as Integrating WordPress to my website, while keeping my own authentication system I am using the below code as requested. It seeks authentication from our ...
1
vote
1answer
336 views

On update to 3.04 site started recording accents as “&Atilde;&iexcl;” and “á”, what to do?

One day my site worked perfectly and the next it suddenly started to have trouble recording accented characters. The problem affects posts' body, if I submit a post with an accent on the title it ...

1
5 6
7
8 9
11