qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
294,153
<p>Is there any hook to change the single product thumbnail? I did search a lot on SO as well as over the internet but no luck.</p> <p>With 'thumbnail' I don't mean changing the size of the current image but I want to completely change/replace the product image (thumbnail) with a new image based on some scenario.</p> ...
[ { "answer_id": 294160, "author": "Mahesh", "author_id": 116626, "author_profile": "https://wordpress.stackexchange.com/users/116626", "pm_score": -1, "selected": false, "text": "<p>I hope this filter will help you.</p>\n\n<pre><code>apply_filters( 'woocommerce_single_product_image_thumbn...
2018/02/15
[ "https://wordpress.stackexchange.com/questions/294153", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/134645/" ]
Is there any hook to change the single product thumbnail? I did search a lot on SO as well as over the internet but no luck. With 'thumbnail' I don't mean changing the size of the current image but I want to completely change/replace the product image (thumbnail) with a new image based on some scenario. ``` public fu...
Here's what I believe is an updated version of one of the other answers' comments. This function replaces the width and height attributes, but OP wanted to change the src. I imagine the solution would be similar, except using preg\_replace to replace the src instead. ``` add_action('woocommerce_single_product_image_th...
294,181
<p>I have noticed Wordpress loves to insert <code>&lt;p&gt;</code> tags everywhere. This can be both helpful and completely annoying...</p> <p>The issue is sometimes i will catch empty <code>&lt;p&gt;</code> tags inserted into the html, which cause a spacing issue (creating more white space on the page..)</p> <p>Inst...
[ { "answer_id": 294182, "author": "Wilco", "author_id": 102737, "author_profile": "https://wordpress.stackexchange.com/users/102737", "pm_score": 3, "selected": true, "text": "<p>I always like to use this in my css:</p>\n\n<pre><code>p:empty{\n\n height: 0;\n\n // or \n display: ...
2018/02/15
[ "https://wordpress.stackexchange.com/questions/294181", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110570/" ]
I have noticed Wordpress loves to insert `<p>` tags everywhere. This can be both helpful and completely annoying... The issue is sometimes i will catch empty `<p>` tags inserted into the html, which cause a spacing issue (creating more white space on the page..) Instead of disabling the `<p>` tag styles all together....
I always like to use this in my css: ``` p:empty{ height: 0; // or display: none; } ``` Keep in mind that this only removes absolutely empty paragraph tags. If there is a space or anything it will not be targeted. More about the empty selector [here](https://www.w3schools.com/cssref/sel_empty.asp)
294,185
<p>I have an old school user who wants to upload an excel file to our Wordpress page.</p> <p>Basically, Wordpress does not allow this.</p> <p>Upon </p> <p><a href="https://gist.github.com/robwent/e3bf00bafe7a00bc3d0c4dceabde4fca" rel="nofollow noreferrer">https://gist.github.com/robwent/e3bf00bafe7a00bc3d0c4dceabde4...
[ { "answer_id": 294198, "author": "sandrodz", "author_id": 115734, "author_profile": "https://wordpress.stackexchange.com/users/115734", "pm_score": 2, "selected": false, "text": "<p>I think the proper filter would be <a href=\"https://developer.wordpress.org/reference/hooks/mime_types/\"...
2018/02/15
[ "https://wordpress.stackexchange.com/questions/294185", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/28354/" ]
I have an old school user who wants to upload an excel file to our Wordpress page. Basically, Wordpress does not allow this. Upon <https://gist.github.com/robwent/e3bf00bafe7a00bc3d0c4dceabde4fca> I put the following into functions.php before the end "Includes": ``` function my_custom_mime_types( $mimes ) { ...
I think the proper filter would be [mime\_types](https://developer.wordpress.org/reference/hooks/mime_types/) found [here](https://core.trac.wordpress.org/browser/tags/4.9.2/src/wp-includes/functions.php#L2401). ``` function wpse294198_mime_types( $mimes ) { $mimes['xls|xlsx'] = 'application/vnd.ms-excel'; ret...
294,186
<p>I want to edit the screen_reader_text in link-template.php Can I do this in a theme so it wont get overwritten on update. It seems a filter is the best option but I cant find documentation on what filter to use.</p> <p>Here is the code I want to change from link-template.php:</p> <pre><code> if ( $GLOBALS['wp...
[ { "answer_id": 294198, "author": "sandrodz", "author_id": 115734, "author_profile": "https://wordpress.stackexchange.com/users/115734", "pm_score": 2, "selected": false, "text": "<p>I think the proper filter would be <a href=\"https://developer.wordpress.org/reference/hooks/mime_types/\"...
2018/02/15
[ "https://wordpress.stackexchange.com/questions/294186", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/14416/" ]
I want to edit the screen\_reader\_text in link-template.php Can I do this in a theme so it wont get overwritten on update. It seems a filter is the best option but I cant find documentation on what filter to use. Here is the code I want to change from link-template.php: ``` if ( $GLOBALS['wp_query']->max_num_pag...
I think the proper filter would be [mime\_types](https://developer.wordpress.org/reference/hooks/mime_types/) found [here](https://core.trac.wordpress.org/browser/tags/4.9.2/src/wp-includes/functions.php#L2401). ``` function wpse294198_mime_types( $mimes ) { $mimes['xls|xlsx'] = 'application/vnd.ms-excel'; ret...
294,203
<p>I keep all hooks in one file, and the functions are organized in their respective classes (different auto-loaded files).</p> <p>Looking for a standard way to document that a function's sole purpose is to be called on 'init' for example.</p> <p>Currently using <code>@see 'init'</code></p> <p>Thanks!</p> <h1>Example C...
[ { "answer_id": 294211, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 1, "selected": false, "text": "<p>Function doc block should document what it does, what it might be useful for, but not who uses it. It mak...
2018/02/15
[ "https://wordpress.stackexchange.com/questions/294203", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/78828/" ]
I keep all hooks in one file, and the functions are organized in their respective classes (different auto-loaded files). Looking for a standard way to document that a function's sole purpose is to be called on 'init' for example. Currently using `@see 'init'` Thanks! Example Code ============ **hooks.php** ```php...
Function doc block should document what it does, what it might be useful for, but not who uses it. It makes sense to document that it was designed with hook X in mind but that is it. Think of unit testing. In that context you are likely to call the function by itself without doing the whole core initialization, which ...
294,223
<p>I am stumped on something I have been working on and would really appreciate any help you can offer.</p> <p>The code below is what elements are to be displayed on a job note. It currently has the users avatar, username, date created and the comment. Both users and administrators(co-workers) can use the notes. If th...
[ { "answer_id": 294227, "author": "terminator", "author_id": 55034, "author_profile": "https://wordpress.stackexchange.com/users/55034", "pm_score": 0, "selected": false, "text": "<p>I think this might work for you </p>\n\n<pre><code>$username = \"terminator\";\n$user = get_user_by('logi...
2018/02/15
[ "https://wordpress.stackexchange.com/questions/294223", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/132977/" ]
I am stumped on something I have been working on and would really appreciate any help you can offer. The code below is what elements are to be displayed on a job note. It currently has the users avatar, username, date created and the comment. Both users and administrators(co-workers) can use the notes. If the username...
@terminator answer might work but there's no need to create an array and use array\_intersect I think since you're only looking for one role. This might be more comprehensible: ``` $current_user = wp_get_current_user(); $roles = (array) $current_user->roles; if (in_array('administrator', $roles) { /* echo whatever */ ...
294,263
<p>Hey guys i'm trying to change the blog title to an image.</p> <p><a href="https://i.stack.imgur.com/cOx1R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cOx1R.png" alt=""></a></p> <p>This is what I'm trying to achieve</p> <p><a href="https://i.stack.imgur.com/VrqGI.jpg" rel="nofollow noreferre...
[ { "answer_id": 294250, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 2, "selected": false, "text": "<p>The straight answer is \"no\" and it is also inpossible to have such a thing as code always depends on so...
2018/02/16
[ "https://wordpress.stackexchange.com/questions/294263", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/-1/" ]
Hey guys i'm trying to change the blog title to an image. [![](https://i.stack.imgur.com/cOx1R.png)](https://i.stack.imgur.com/cOx1R.png) This is what I'm trying to achieve [![](https://i.stack.imgur.com/VrqGI.jpg)](https://i.stack.imgur.com/VrqGI.jpg) I tried adding this code to the css and it's working. ``` .rh-...
The straight answer is "no" and it is also inpossible to have such a thing as code always depends on some DB format, and you can not just change the code without the DB. What happens when you upgrade over several releases will depend on the quality of the plugins and the testings being done to them. You can almost alw...
294,318
<p>I have the following bit of code that is called from the the <code>the_post</code> hook. This code works fine on one of our live sites, but I'm trying to develop the plugin further locally and this is no longer working.</p> <pre><code>public function fetch_post_data( $post ) { $post-&gt;post_content = 'This is a...
[ { "answer_id": 294319, "author": "Kevin", "author_id": 27041, "author_profile": "https://wordpress.stackexchange.com/users/27041", "pm_score": 0, "selected": false, "text": "<p>I was able to solve this with the following. I don't know if this is proper, and I don't really understand why ...
2018/02/16
[ "https://wordpress.stackexchange.com/questions/294318", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/27041/" ]
I have the following bit of code that is called from the the `the_post` hook. This code works fine on one of our live sites, but I'm trying to develop the plugin further locally and this is no longer working. ``` public function fetch_post_data( $post ) { $post->post_content = 'This is a test.'; } add_action('the_...
`get_the_content()` doesn't actually return the `post_content` property from the global `$post` object. Instead it returns the first page of the global variable `$pages`, which is set before `the_post` hook is fired. See [L287 of wp-includes/post-template](https://core.trac.wordpress.org/browser/tags/4.9/src/wp-include...
294,321
<p>I'm trying to build a gutenberg block (via plugin) that interfaces with a third-party api via credentials. I'm unsure how to, or even if I can, access a plugin's settings in gutenberg in order to grab a potential credentials field for use in the block. (I understand there's potential to put something in the editor's...
[ { "answer_id": 300042, "author": "Nathan Johnson", "author_id": 106269, "author_profile": "https://wordpress.stackexchange.com/users/106269", "pm_score": 4, "selected": true, "text": "<p>The WordPress way to access PHP variables with JavaScript is to use <a href=\"https://developer.wordp...
2018/02/16
[ "https://wordpress.stackexchange.com/questions/294321", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/98703/" ]
I'm trying to build a gutenberg block (via plugin) that interfaces with a third-party api via credentials. I'm unsure how to, or even if I can, access a plugin's settings in gutenberg in order to grab a potential credentials field for use in the block. (I understand there's potential to put something in the editor's si...
The WordPress way to access PHP variables with JavaScript is to use [`wp_localize_script()`](https://developer.wordpress.org/reference/functions/wp_localize_script/). ``` function wpse_enqueue_scripts(){ wp_enqueue_script( 'wpse', PATH_TO . 'script.js' ); wp_localize_script( 'wpse', 'credentials', $credentials ); ...
294,324
<p>i want to make a little Header with the 3 recent thumbnails in different sizes and start my loop with the 4th recent posts, can someone give me a function for that please? please no widgets i want to make it raw and get more into webdesign.</p> <p>U can see how it looks on my page: <a href="http://web91.s67.goserve...
[ { "answer_id": 300042, "author": "Nathan Johnson", "author_id": 106269, "author_profile": "https://wordpress.stackexchange.com/users/106269", "pm_score": 4, "selected": true, "text": "<p>The WordPress way to access PHP variables with JavaScript is to use <a href=\"https://developer.wordp...
2018/02/16
[ "https://wordpress.stackexchange.com/questions/294324", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137014/" ]
i want to make a little Header with the 3 recent thumbnails in different sizes and start my loop with the 4th recent posts, can someone give me a function for that please? please no widgets i want to make it raw and get more into webdesign. U can see how it looks on my page: <http://web91.s67.goserver.host/> the 3 gr...
The WordPress way to access PHP variables with JavaScript is to use [`wp_localize_script()`](https://developer.wordpress.org/reference/functions/wp_localize_script/). ``` function wpse_enqueue_scripts(){ wp_enqueue_script( 'wpse', PATH_TO . 'script.js' ); wp_localize_script( 'wpse', 'credentials', $credentials ); ...
294,327
<p>I have seen the token %1$ and similar ones more often in the WordPress code lately, but I can't figure out what it means. Here an example:</p> <pre><code>sprintf( __( '%1$s is deprecated. Use %2$s instead.' ), </code></pre> <p>Does anyone know what it means?</p>
[ { "answer_id": 294330, "author": "Pat J", "author_id": 16121, "author_profile": "https://wordpress.stackexchange.com/users/16121", "pm_score": 3, "selected": false, "text": "<p>It's not a WordPress thing, it's a PHP thing. <code>%1$s</code>, <code>%2$s</code>, etc., are placeholders for ...
2018/02/16
[ "https://wordpress.stackexchange.com/questions/294327", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/136032/" ]
I have seen the token %1$ and similar ones more often in the WordPress code lately, but I can't figure out what it means. Here an example: ``` sprintf( __( '%1$s is deprecated. Use %2$s instead.' ), ``` Does anyone know what it means?
Read the [PHP docs on sprintf()](http://php.net/manual/en/function.sprintf.php). * `%s` is just a placeholder for a string * `%d` is just a placeholder for a number So an example of sprintf would look like this: ``` $variable = sprintf( 'The %s ran down the %s', // String with placeholders 'dog', // P...
294,352
<p>I am trying post submit on front end. All works without thumbnail uploading and setting. Here is my html form.</p> <pre><code>&lt;form method="post" action=""&gt; &lt;input type="text" name="title"&gt; &lt;textarea name="content"&gt;&lt;/textarea&gt; &lt;input type="file" name="thumbnail"&gt; &lt;in...
[ { "answer_id": 294392, "author": "Stefano Tombolini", "author_id": 96268, "author_profile": "https://wordpress.stackexchange.com/users/96268", "pm_score": 0, "selected": false, "text": "<p>There seem to be some unnecessary code. Try the following one:</p>\n\n<pre><code>$title = $_POST[...
2018/02/16
[ "https://wordpress.stackexchange.com/questions/294352", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/133897/" ]
I am trying post submit on front end. All works without thumbnail uploading and setting. Here is my html form. ``` <form method="post" action=""> <input type="text" name="title"> <textarea name="content"></textarea> <input type="file" name="thumbnail"> <input type="submit" name="submit"> </form> ``` ...
In form, you need the code enctype="multipart/form-data" ``` <form method="post" action="" enctype="multipart/form-data"> ```
294,356
<p>I want that email reply should be received at multiple email address. But it is not working for me. I have tried different ways but none of these working for me. I am trying this header but it is only replying to the last email address.</p> <pre><code>$to = "recipientemail@address.com"; $subject = "my email subjec...
[ { "answer_id": 294357, "author": "Tom J Nowell", "author_id": 736, "author_profile": "https://wordpress.stackexchange.com/users/736", "pm_score": 4, "selected": true, "text": "<p><strong>Unfortunately this is not widely supported</strong>, not because WordPress does not support it, but b...
2018/02/17
[ "https://wordpress.stackexchange.com/questions/294356", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/120693/" ]
I want that email reply should be received at multiple email address. But it is not working for me. I have tried different ways but none of these working for me. I am trying this header but it is only replying to the last email address. ``` $to = "recipientemail@address.com"; $subject = "my email subject"; $message =...
**Unfortunately this is not widely supported**, not because WordPress does not support it, but because most email clients do not support it, so it cannot be relied upon. Instead, consider using a mailing list and use the mailing lists address as the reply to field
294,394
<p>I'm trying to add a custom data attribute to the <code>&lt;a&gt;</code> element. What I'm trying to do is integrate the navigation effect in this <a href="https://codepen.io/littlesnippets/pen/pjmXvP" rel="nofollow noreferrer">CodePen</a></p> <p>I can do all the CSS but I need to add the HTML part such as below:</p...
[ { "answer_id": 294398, "author": "Den Isahac", "author_id": 113233, "author_profile": "https://wordpress.stackexchange.com/users/113233", "pm_score": 1, "selected": false, "text": "<p>If you want to add a custom <code>data</code> attributes to the menu that's generated by <a href=\"https...
2018/02/17
[ "https://wordpress.stackexchange.com/questions/294394", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/125303/" ]
I'm trying to add a custom data attribute to the `<a>` element. What I'm trying to do is integrate the navigation effect in this [CodePen](https://codepen.io/littlesnippets/pen/pjmXvP) I can do all the CSS but I need to add the HTML part such as below: ``` <ul class="snip1226"> <li class="current"><a href="#" da...
If you want to add a custom `data` attributes to the menu that's generated by [`wp_nav_menu`](https://developer.wordpress.org/reference/functions/wp_nav_menu/) function. You can use the [`nav_menu_link_attributes`](https://developer.wordpress.org/reference/hooks/nav_menu_link_attributes/) filter to add the desired attr...
294,413
<p>Bonsouir, I'm trying to redirect to checkout when a user add to cart a product just from the single product page, to be very specific from this page where everyone can see just the simple product</p> <p><a href="https://i.stack.imgur.com/u6U8U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u6U8U...
[ { "answer_id": 294470, "author": "Aadil P.", "author_id": 49322, "author_profile": "https://wordpress.stackexchange.com/users/49322", "pm_score": 0, "selected": false, "text": "<p>The function is_product() and/or is_single() can only identify the page after wp_query() is ready.\nApparent...
2018/02/17
[ "https://wordpress.stackexchange.com/questions/294413", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/130802/" ]
Bonsouir, I'm trying to redirect to checkout when a user add to cart a product just from the single product page, to be very specific from this page where everyone can see just the simple product [![enter image description here](https://i.stack.imgur.com/u6U8U.png)](https://i.stack.imgur.com/u6U8U.png) Now, everythin...
Well, what it works for me in this case was this code ``` add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_add_to_cart' ); function redirect_add_to_cart() { if ( isset( $_POST['add-to-cart'] ) ) { $url = wc_get_checkout_url(); return $url; } } ``` It redirects if it is...
294,414
<p>I have two number and an operator in three variables. For example $number1, $number2 and $operator. $operator contains only an operator from an array of (+, -, *, /). Now my question is how can I calculate mathematical operation with these three variables? For example $number1 ($operator) $number2 = ?</p>
[ { "answer_id": 294415, "author": "Beee", "author_id": 103402, "author_profile": "https://wordpress.stackexchange.com/users/103402", "pm_score": -1, "selected": false, "text": "<p>I think it can be done very simple, if I understand it correctly.</p>\n\n<pre><code>$operators = array( '+', ...
2018/02/18
[ "https://wordpress.stackexchange.com/questions/294414", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/136361/" ]
I have two number and an operator in three variables. For example $number1, $number2 and $operator. $operator contains only an operator from an array of (+, -, \*, /). Now my question is how can I calculate mathematical operation with these three variables? For example $number1 ($operator) $number2 = ?
Recommend you just stick to `*` and `+`, not expect people to deal with decimals and negative numbers. It is best to keep it simple as possible and not attempt to `eval` the string as an expression which is not good practice: ``` $operators = array('+', '*'); $operator = rand(0, 1); $display = $number1.' '.$operators[...
294,419
<p>This is a doozy, you’ll like it. Since about a week ago, when I edit a post, if that post contains a hyperlink (eg <code>&lt;a href="..."&gt;...&lt;/a&gt;</code>) when I update it, I’m sent to the 404 “Page not Found” page, and the post is NOT saved. Here’s a video: <a href="https://drive.google.com/file/d/1OQZ9k5f_...
[ { "answer_id": 294415, "author": "Beee", "author_id": 103402, "author_profile": "https://wordpress.stackexchange.com/users/103402", "pm_score": -1, "selected": false, "text": "<p>I think it can be done very simple, if I understand it correctly.</p>\n\n<pre><code>$operators = array( '+', ...
2018/02/18
[ "https://wordpress.stackexchange.com/questions/294419", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/52760/" ]
This is a doozy, you’ll like it. Since about a week ago, when I edit a post, if that post contains a hyperlink (eg `<a href="...">...</a>`) when I update it, I’m sent to the 404 “Page not Found” page, and the post is NOT saved. Here’s a video: <https://drive.google.com/file/d/1OQZ9k5f_jxbxsT4SEyD-pH28FSIMoQlT/view>. I...
Recommend you just stick to `*` and `+`, not expect people to deal with decimals and negative numbers. It is best to keep it simple as possible and not attempt to `eval` the string as an expression which is not good practice: ``` $operators = array('+', '*'); $operator = rand(0, 1); $display = $number1.' '.$operators[...
294,464
<p>This is my Code</p> <pre><code>if($totalPage &gt; 1){ $customPagHTML = paginate_links( array( 'base' =&gt; add_query_arg( 'cp', '%#%' ), 'format' =&gt; '', 'prev_text' =&gt; __('Back', '&amp;laquo;'), 'next_text' =&gt; __('Next', '&amp;raquo;'), 'total' ...
[ { "answer_id": 294415, "author": "Beee", "author_id": 103402, "author_profile": "https://wordpress.stackexchange.com/users/103402", "pm_score": -1, "selected": false, "text": "<p>I think it can be done very simple, if I understand it correctly.</p>\n\n<pre><code>$operators = array( '+', ...
2018/02/19
[ "https://wordpress.stackexchange.com/questions/294464", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/136190/" ]
This is my Code ``` if($totalPage > 1){ $customPagHTML = paginate_links( array( 'base' => add_query_arg( 'cp', '%#%' ), 'format' => '', 'prev_text' => __('Back', '&laquo;'), 'next_text' => __('Next', '&raquo;'), 'total' => $totalPage, 'current' =>...
Recommend you just stick to `*` and `+`, not expect people to deal with decimals and negative numbers. It is best to keep it simple as possible and not attempt to `eval` the string as an expression which is not good practice: ``` $operators = array('+', '*'); $operator = rand(0, 1); $display = $number1.' '.$operators[...
294,480
<p>I am modifying a WordPress theme, but the problem is every time I edit my CSS file via FileZilla and upload it to the server, the CSS file doesn't get updated immediately after browser refresh and it's very frustrating.</p> <p>I get the idea that the CSS <code>ver</code> tag is helping browser not to cache old CSS ...
[ { "answer_id": 294483, "author": "obiPlabon", "author_id": 135737, "author_profile": "https://wordpress.stackexchange.com/users/135737", "pm_score": 2, "selected": false, "text": "<p>You're facing browser caching problem and it's not because of <code>ver</code>. Every time you update you...
2018/02/19
[ "https://wordpress.stackexchange.com/questions/294480", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/125422/" ]
I am modifying a WordPress theme, but the problem is every time I edit my CSS file via FileZilla and upload it to the server, the CSS file doesn't get updated immediately after browser refresh and it's very frustrating. I get the idea that the CSS `ver` tag is helping browser not to cache old CSS files, but for the te...
You're facing browser caching problem and it's not because of `ver`. Every time you update your CSS or JS files you should hard refresh your browser using `Ctrl + Shift + R` or you can change the `ver` value. If the default `ver` is `ver=1.0.0` then update the `ver` to `ver=1.0.1`. The point is, change the `ver` value ...
294,568
<p>I've read a lot of questions about this topic. None of them solve my issue.</p> <p><strong>Poblem</strong>: pagination is shown at page 1 but page 2 returns 404.</p> <p>The query and loop are in front-page.php:</p> <pre><code>// WP_Query arguments $args = array( 'post_type' =&gt; 'trabajo', 'post...
[ { "answer_id": 294573, "author": "aitor", "author_id": 77722, "author_profile": "https://wordpress.stackexchange.com/users/77722", "pm_score": 1, "selected": false, "text": "<p>I found here a workaround: <a href=\"https://wordpress.stackexchange.com/questions/22528/custom-post-type-pagin...
2018/02/20
[ "https://wordpress.stackexchange.com/questions/294568", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/77722/" ]
I've read a lot of questions about this topic. None of them solve my issue. **Poblem**: pagination is shown at page 1 but page 2 returns 404. The query and loop are in front-page.php: ``` // WP_Query arguments $args = array( 'post_type' => 'trabajo', 'posts_per_page' => '2', 'paged' ...
I found the final answer here: <https://wordpress.stackexchange.com/a/217534/77722> Page 2 of front page was taking pagination from main query, not from my custom query. I've taked these actions: **1. To change name of front-page.php to index.php** in order to get the main query every time page is loaded (even when ...
294,575
<p>I recently imported large number of custom posts into wordpress. all works fine, except one taxonomy which is imported, but not show at the front end, until i click on every post "update" button. I have 810 posts and this is not a solution...</p> <p>i think it should be the way to run MYSQL command to force all pos...
[ { "answer_id": 294579, "author": "Clinton", "author_id": 122375, "author_profile": "https://wordpress.stackexchange.com/users/122375", "pm_score": 3, "selected": false, "text": "<p>There are 2 ways that you could do this. The first and more difficult is to write a program, the other is t...
2018/02/20
[ "https://wordpress.stackexchange.com/questions/294575", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137182/" ]
I recently imported large number of custom posts into wordpress. all works fine, except one taxonomy which is imported, but not show at the front end, until i click on every post "update" button. I have 810 posts and this is not a solution... i think it should be the way to run MYSQL command to force all post update w...
There are 2 ways that you could do this. The first and more difficult is to write a program, the other is to do a bulk update. Why do difficult when easy way will work equally well? and especially as this is a once-off requirement The easy way: 1. In the admin dashboard, select the view with all posts for your custom...
294,582
<p><a href="https://codex.wordpress.org/index.php?title=Creating_Options_Pages&amp;oldid=97268" rel="nofollow noreferrer">https://codex.wordpress.org/index.php?title=Creating_Options_Pages&amp;oldid=97268</a></p> <p>This page shows how to create options pages.</p> <pre><code> // theme-settings.php &lt...
[ { "answer_id": 294579, "author": "Clinton", "author_id": 122375, "author_profile": "https://wordpress.stackexchange.com/users/122375", "pm_score": 3, "selected": false, "text": "<p>There are 2 ways that you could do this. The first and more difficult is to write a program, the other is t...
2018/02/20
[ "https://wordpress.stackexchange.com/questions/294582", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137188/" ]
<https://codex.wordpress.org/index.php?title=Creating_Options_Pages&oldid=97268> This page shows how to create options pages. ``` // theme-settings.php <?php add_action('admin_menu', 'talimiboard_register_menu_and_page'); function talimiboard_register_menu_and_page() { add_theme_...
There are 2 ways that you could do this. The first and more difficult is to write a program, the other is to do a bulk update. Why do difficult when easy way will work equally well? and especially as this is a once-off requirement The easy way: 1. In the admin dashboard, select the view with all posts for your custom...
294,600
<p>I need to use Paper.js (<a href="http://paperjs.org/" rel="nofollow noreferrer">http://paperjs.org/</a>), and specifically one of their examples (<a href="http://paperjs.org/examples/smoothing/" rel="nofollow noreferrer">http://paperjs.org/examples/smoothing/</a>) on a WordPress website.</p> <p>Usually, scripts are...
[ { "answer_id": 294629, "author": "Nathan Johnson", "author_id": 106269, "author_profile": "https://wordpress.stackexchange.com/users/106269", "pm_score": 3, "selected": true, "text": "<p>I'm not sure if this will solve your problem, but you can use the <code>script_loader_tag</code> filt...
2018/02/20
[ "https://wordpress.stackexchange.com/questions/294600", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/128875/" ]
I need to use Paper.js (<http://paperjs.org/>), and specifically one of their examples (<http://paperjs.org/examples/smoothing/>) on a WordPress website. Usually, scripts are enqued to WP with a PHP function that adds scripts of type text/javascript (<https://developer.wordpress.org/reference/functions/wp_enqueue_scri...
I'm not sure if this will solve your problem, but you can use the `script_loader_tag` filter to change the type `text/javascript` to `text/paperscript` ``` add_filter( 'script_loader_tag', function( $tag, $handle, $src ) { if( 'your-script-handle' === $handle ) { $tag = str_replace( 'text/javascript', 'text/pape...
294,612
<p>I have a custom post type named houses. Inside my custom post type I have several custom fields which I created using ACF.</p> <p>What I need to do is to change the permalink when I create a new post.</p> <p>I would like to use the <strong>code</strong> and <strong>title</strong> fields to customize the permalink:...
[ { "answer_id": 294629, "author": "Nathan Johnson", "author_id": 106269, "author_profile": "https://wordpress.stackexchange.com/users/106269", "pm_score": 3, "selected": true, "text": "<p>I'm not sure if this will solve your problem, but you can use the <code>script_loader_tag</code> filt...
2018/02/20
[ "https://wordpress.stackexchange.com/questions/294612", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/133606/" ]
I have a custom post type named houses. Inside my custom post type I have several custom fields which I created using ACF. What I need to do is to change the permalink when I create a new post. I would like to use the **code** and **title** fields to customize the permalink: ``` //code + post title 4563312-house-exa...
I'm not sure if this will solve your problem, but you can use the `script_loader_tag` filter to change the type `text/javascript` to `text/paperscript` ``` add_filter( 'script_loader_tag', function( $tag, $handle, $src ) { if( 'your-script-handle' === $handle ) { $tag = str_replace( 'text/javascript', 'text/pape...
294,613
<p>I'm creating a plugin that supports internationalization.</p> <p>Everything is working fine, except for global variables.</p> <p>Strings in global variables will not get the appropriate translation.</p> <p>Explanation:</p> <pre><code>_e('Hello World','text-domain'); // Gets translated $var = __('Hello Global Wo...
[ { "answer_id": 294618, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 1, "selected": false, "text": "<p>In general you should not have global variables.</p>\n\n<p>Specifically, if your file is not loaded at th...
2018/02/20
[ "https://wordpress.stackexchange.com/questions/294613", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109855/" ]
I'm creating a plugin that supports internationalization. Everything is working fine, except for global variables. Strings in global variables will not get the appropriate translation. Explanation: ``` _e('Hello World','text-domain'); // Gets translated $var = __('Hello Global World','text-domain'); function fun()...
Translation works with global variables, you just need to wait until the proper hook to call the translation functions. I haven't looked at the code or documentation, but just by experimenting, the translations are loaded sometime before the `after_setup_theme` hook, but after the other hooks that fire before that. Th...
294,623
<p>I am trying to use the jQuery Datatables plugin in my WordPress dashboard but the native WordPress admin CSS styling is overiding the datatables CSS, I am calling them like this...</p> <pre><code>add_action('admin_enqueue_scripts', 'admin_scripts'); function admin_scripts() { wp_enqueue_script('datatables', '//...
[ { "answer_id": 294624, "author": "Cedon", "author_id": 80069, "author_profile": "https://wordpress.stackexchange.com/users/80069", "pm_score": 1, "selected": false, "text": "<p>By default they should already be loading after the core admin styles. I suspect the CSS isn't even being loade...
2018/02/20
[ "https://wordpress.stackexchange.com/questions/294623", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/10247/" ]
I am trying to use the jQuery Datatables plugin in my WordPress dashboard but the native WordPress admin CSS styling is overiding the datatables CSS, I am calling them like this... ``` add_action('admin_enqueue_scripts', 'admin_scripts'); function admin_scripts() { wp_enqueue_script('datatables', '//cdn.datatables...
By default they should already be loading after the core admin styles. I suspect the CSS isn't even being loaded because you have an invalid parameter in your `wp_enqueue_style()` call. Its parameters are the same as `wp_enqueue_script()`. Where you have `99` is where dependencies are actually defined. So WordPress is ...
294,644
<p>First, sorry my english. I am using Local by flywheel to manager my site files and my wordpress version is 4.9.4.</p> <p>Here is the problem, When I use</p> <pre><code> wp_enqueue_style('wharever', get_stylesheet_uri()); </code></pre> <p>To load style.css at the first time with a just simple content inside:</p> ...
[ { "answer_id": 294656, "author": "n8bar", "author_id": 116579, "author_profile": "https://wordpress.stackexchange.com/users/116579", "pm_score": 1, "selected": false, "text": "<p>It is a caching problem. To get around this I append a random string to the stylesheet uri that discourages ...
2018/02/20
[ "https://wordpress.stackexchange.com/questions/294644", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137223/" ]
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()); ``` To load style.css at the first time with a just simple content inside: ``` body { color: orange; } ``` Eve...
Another solution is to use `filemtime` for the cachebusting, so that the last modified timestamp is used as the querystring variable. This has the advantage that of still using the browser cache, and yet, a new file is served when the file is actually changed because the querystring changes. eg. ``` $lastmodtime= fi...
294,671
<p>I made a custom post type, say ‘movie’, using "custom type post UI" plugin, and linked it with built-in category. Both normal posts and custom type posts are in the same category. My question is that if it is possible to modify the existing counting function so that it counts the number of posts that does not have a...
[ { "answer_id": 294656, "author": "n8bar", "author_id": 116579, "author_profile": "https://wordpress.stackexchange.com/users/116579", "pm_score": 1, "selected": false, "text": "<p>It is a caching problem. To get around this I append a random string to the stylesheet uri that discourages ...
2018/02/21
[ "https://wordpress.stackexchange.com/questions/294671", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137244/" ]
I made a custom post type, say ‘movie’, using "custom type post UI" plugin, and linked it with built-in category. Both normal posts and custom type posts are in the same category. My question is that if it is possible to modify the existing counting function so that it counts the number of posts that does not have a po...
Another solution is to use `filemtime` for the cachebusting, so that the last modified timestamp is used as the querystring variable. This has the advantage that of still using the browser cache, and yet, a new file is served when the file is actually changed because the querystring changes. eg. ``` $lastmodtime= fi...
294,676
<p>I have a Wordpress site, I have the Front Page settings right in the Reading settings, but when I goto my Wordpress site and I am not login, I get a 404 error and my page looks messed up. When I am login to Wordpress my Front Page looks like it should and I dont get a 404 page. Here is my site, why is this happening...
[ { "answer_id": 294656, "author": "n8bar", "author_id": 116579, "author_profile": "https://wordpress.stackexchange.com/users/116579", "pm_score": 1, "selected": false, "text": "<p>It is a caching problem. To get around this I append a random string to the stylesheet uri that discourages ...
2018/02/21
[ "https://wordpress.stackexchange.com/questions/294676", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/19080/" ]
I have a Wordpress site, I have the Front Page settings right in the Reading settings, but when I goto my Wordpress site and I am not login, I get a 404 error and my page looks messed up. When I am login to Wordpress my Front Page looks like it should and I dont get a 404 page. Here is my site, why is this happening? ...
Another solution is to use `filemtime` for the cachebusting, so that the last modified timestamp is used as the querystring variable. This has the advantage that of still using the browser cache, and yet, a new file is served when the file is actually changed because the querystring changes. eg. ``` $lastmodtime= fi...
294,735
<p>I have a search bar on 2 pages in my site and on my page called archive I want to exclude a category called economics (id - 9) from the search. I have placed this in my functions.php file:</p> <pre><code>function archive_search_filter( $query ) { if ( $query-&gt;is_search &amp;&amp; $query-&gt;is_main_query() ) {...
[ { "answer_id": 294656, "author": "n8bar", "author_id": 116579, "author_profile": "https://wordpress.stackexchange.com/users/116579", "pm_score": 1, "selected": false, "text": "<p>It is a caching problem. To get around this I append a random string to the stylesheet uri that discourages ...
2018/02/21
[ "https://wordpress.stackexchange.com/questions/294735", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/127290/" ]
I have a search bar on 2 pages in my site and on my page called archive I want to exclude a category called economics (id - 9) from the search. I have placed this in my functions.php file: ``` function archive_search_filter( $query ) { if ( $query->is_search && $query->is_main_query() ) { $query->set( 'category__n...
Another solution is to use `filemtime` for the cachebusting, so that the last modified timestamp is used as the querystring variable. This has the advantage that of still using the browser cache, and yet, a new file is served when the file is actually changed because the querystring changes. eg. ``` $lastmodtime= fi...
294,787
<p>I have looked online and found different pieces of code together but unable to find a solution that holds up.</p> <p>Basically i need to display 10 posts in total, but the first three need to be random.</p> <p>This is what I have so far (taken from a similar question).</p> <pre><code>$args = array( 'post_typ...
[ { "answer_id": 294788, "author": "Rick Hellewell", "author_id": 29416, "author_profile": "https://wordpress.stackexchange.com/users/29416", "pm_score": 0, "selected": false, "text": "<p>Perhaps this psuedocode in the Loop:</p>\n\n<pre><code>// set up a counter\n// the WP Loop\n // if c...
2018/02/21
[ "https://wordpress.stackexchange.com/questions/294787", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137320/" ]
I have looked online and found different pieces of code together but unable to find a solution that holds up. Basically i need to display 10 posts in total, but the first three need to be random. This is what I have so far (taken from a similar question). ``` $args = array( 'post_type' => 'post', 'posts_pe...
Try this: ``` // All the rendered HTML $output = ''; // The posts to exclude from the random query. $exclude = []; // The remaining non-random posts $remaining = new WP_Query([ 'posts_per_page' => 7, ]); // Run the remaining query first because we have to know what should be excluded in the random query. if {$r...
294,822
<p>I have here hardcoded category id so I can pull in needed categories and their posts by category. But ideally I would like to get this by calling parent category to list child and post. My code works but that's not how I would like to do it and would like to hear any suggestions to improve. I'm still trying to figur...
[ { "answer_id": 294788, "author": "Rick Hellewell", "author_id": 29416, "author_profile": "https://wordpress.stackexchange.com/users/29416", "pm_score": 0, "selected": false, "text": "<p>Perhaps this psuedocode in the Loop:</p>\n\n<pre><code>// set up a counter\n// the WP Loop\n // if c...
2018/02/22
[ "https://wordpress.stackexchange.com/questions/294822", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/135938/" ]
I have here hardcoded category id so I can pull in needed categories and their posts by category. But ideally I would like to get this by calling parent category to list child and post. My code works but that's not how I would like to do it and would like to hear any suggestions to improve. I'm still trying to figure t...
Try this: ``` // All the rendered HTML $output = ''; // The posts to exclude from the random query. $exclude = []; // The remaining non-random posts $remaining = new WP_Query([ 'posts_per_page' => 7, ]); // Run the remaining query first because we have to know what should be excluded in the random query. if {$r...
294,823
<p>As the title says, How can I add a custom CSS to all posts without affecting homepage CSS on WordPress?</p> <p>And I know that some plugins like "WP Add Custom CSS" would work for this and I am actually using it, and it does work but, what I want to do is give all my posts the same exact code, I don't want to give ...
[ { "answer_id": 294825, "author": "kero", "author_id": 108180, "author_profile": "https://wordpress.stackexchange.com/users/108180", "pm_score": 4, "selected": true, "text": "<p>By default, WordPress sets various classes to <code>&lt;body&gt;</code> depending on which page, template, pare...
2018/02/22
[ "https://wordpress.stackexchange.com/questions/294823", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137346/" ]
As the title says, How can I add a custom CSS to all posts without affecting homepage CSS on WordPress? And I know that some plugins like "WP Add Custom CSS" would work for this and I am actually using it, and it does work but, what I want to do is give all my posts the same exact code, I don't want to give every post...
By default, WordPress sets various classes to `<body>` depending on which page, template, parent, .. you are on. For a single post, some of these are `single` and `single-post`, so you could use the following ``` body.single.single-post .post-meta { margin-right: 0px !important; } ```
294,842
<p>I created a plugin which uses bootstrap datetimepicker. So i load corresponding js setting dependancies like this:</p> <pre><code>wp_enqueue_script('medapp-datetimepicker-js', $medapp_boot_timepicker_js, array( 'jquery', 'jquery-ui', 'moment', 'medapp-...
[ { "answer_id": 294844, "author": "WebElaine", "author_id": 102815, "author_profile": "https://wordpress.stackexchange.com/users/102815", "pm_score": 1, "selected": false, "text": "<p>Basic JS troubleshooting - strip it down to basics. Create a new script which either has a <code>console....
2018/02/22
[ "https://wordpress.stackexchange.com/questions/294842", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/108789/" ]
I created a plugin which uses bootstrap datetimepicker. So i load corresponding js setting dependancies like this: ``` wp_enqueue_script('medapp-datetimepicker-js', $medapp_boot_timepicker_js, array( 'jquery', 'jquery-ui', 'moment', 'medapp-twitter-bootst...
Basic JS troubleshooting - strip it down to basics. Create a new script which either has a `console.log('I am working')` or `alert('I am working')` and enqueue it without any dependencies. If it works, enqueue it with your dependencies - still with your console or alert to easily check whether it's working. If it works...
294,868
<p>I'd like to add that nice little notification bubble beside a nav item in the admin. But I don't want to slow down the whole admin by triggering a post query every time just to display the value in the little bubble. Hoping to load this one integer value into transient cache to use for display in the menu.</p> <p>D...
[ { "answer_id": 294983, "author": "jdm2112", "author_id": 45202, "author_profile": "https://wordpress.stackexchange.com/users/45202", "pm_score": 1, "selected": false, "text": "<p>Using your original code, I pulled the query/count/cache code to a separate function. I have not had a chan...
2018/02/22
[ "https://wordpress.stackexchange.com/questions/294868", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8689/" ]
I'd like to add that nice little notification bubble beside a nav item in the admin. But I don't want to slow down the whole admin by triggering a post query every time just to display the value in the little bubble. Hoping to load this one integer value into transient cache to use for display in the menu. Developing ...
Thanks again for the help @jdm2112. Updated a few syntax errors and used the same structure you suggested, works great! ``` // Add notification bubble to custom post type menu nav add_action( 'admin_menu', 'add_cpt_menu_bubble' ); function add_cpt_menu_bubble() { global $menu; $count_posts = tms_count_pending...
294,880
<p>How do I display a different group of photos with each blog post without uploading the photos to the Wordpress Media Library?</p> <p>I’m using Wordpress for my blog. The blog is sort of a diary. One blog per day. The post title is each day’s date, in the format yyyymmdd. For each blog post, I take 10-50 photos. All...
[ { "answer_id": 294983, "author": "jdm2112", "author_id": 45202, "author_profile": "https://wordpress.stackexchange.com/users/45202", "pm_score": 1, "selected": false, "text": "<p>Using your original code, I pulled the query/count/cache code to a separate function. I have not had a chan...
2018/02/22
[ "https://wordpress.stackexchange.com/questions/294880", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137390/" ]
How do I display a different group of photos with each blog post without uploading the photos to the Wordpress Media Library? I’m using Wordpress for my blog. The blog is sort of a diary. One blog per day. The post title is each day’s date, in the format yyyymmdd. For each blog post, I take 10-50 photos. All the photo...
Thanks again for the help @jdm2112. Updated a few syntax errors and used the same structure you suggested, works great! ``` // Add notification bubble to custom post type menu nav add_action( 'admin_menu', 'add_cpt_menu_bubble' ); function add_cpt_menu_bubble() { global $menu; $count_posts = tms_count_pending...
294,907
<p>Currently, I can only get the post by user roles on specific sites. What I need is to have a query that will get the post from user role on other site.</p> <pre><code>Example Users: Site A - user(admin site a, editor site a) Site B - user(editor site b) Site C - user(editor site c) </code></pre> <blockquote> <p>...
[ { "answer_id": 294908, "author": "Mohit Kumar", "author_id": 111870, "author_profile": "https://wordpress.stackexchange.com/users/111870", "pm_score": -1, "selected": false, "text": "<p>As per your questions, I think you want to call separate php file (my-plugin.php) on plugin menu clic...
2018/02/23
[ "https://wordpress.stackexchange.com/questions/294907", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137408/" ]
Currently, I can only get the post by user roles on specific sites. What I need is to have a query that will get the post from user role on other site. ``` Example Users: Site A - user(admin site a, editor site a) Site B - user(editor site b) Site C - user(editor site c) ``` > > Site A - index list of posts > > >...
Generaly no, or at least if you work hard enough to make it happen it will make much more sense to just use `mydomain.com/wp-admin/my-plugin` (without the php extension). The reason is that by default the htaccess rules wordpress uses, first try to locate a file in the implied path, and if it is not there it "fires" t...
294,922
<p>I am using the auto_core_update_email hook to modify the auto update email sent by WordPress. However I cannot figure out how to add line breaks to the email body. Here's my code:</p> <pre><code>function example_filter_auto_update_email($email) { $email['to'] = array('example@example.com', 'test@example.com'...
[ { "answer_id": 294908, "author": "Mohit Kumar", "author_id": 111870, "author_profile": "https://wordpress.stackexchange.com/users/111870", "pm_score": -1, "selected": false, "text": "<p>As per your questions, I think you want to call separate php file (my-plugin.php) on plugin menu clic...
2018/02/23
[ "https://wordpress.stackexchange.com/questions/294922", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/135943/" ]
I am using the auto\_core\_update\_email hook to modify the auto update email sent by WordPress. However I cannot figure out how to add line breaks to the email body. Here's my code: ``` function example_filter_auto_update_email($email) { $email['to'] = array('example@example.com', 'test@example.com'); $email[...
Generaly no, or at least if you work hard enough to make it happen it will make much more sense to just use `mydomain.com/wp-admin/my-plugin` (without the php extension). The reason is that by default the htaccess rules wordpress uses, first try to locate a file in the implied path, and if it is not there it "fires" t...
294,946
<p>I synchronize some data of my plugin with an extern API. This synchronize-process should fire every minute. So I use the following code to do that:</p> <pre><code>if ( ! get_transient( 'my_task_sync_method' ) ) { set_transient( 'my_task_sync_method', true, 1 * MINUTE_IN_SECONDS ); my_task_sync_method(); } <...
[ { "answer_id": 294966, "author": "David Sword", "author_id": 132362, "author_profile": "https://wordpress.stackexchange.com/users/132362", "pm_score": 3, "selected": true, "text": "<p>To my understanding, <code>*_transient()</code> is basically <code>*_option()</code> wrapped in a cache-...
2018/02/23
[ "https://wordpress.stackexchange.com/questions/294946", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/80958/" ]
I synchronize some data of my plugin with an extern API. This synchronize-process should fire every minute. So I use the following code to do that: ``` if ( ! get_transient( 'my_task_sync_method' ) ) { set_transient( 'my_task_sync_method', true, 1 * MINUTE_IN_SECONDS ); my_task_sync_method(); } ``` Currently...
To my understanding, `*_transient()` is basically `*_option()` wrapped in a cache-timer. What that means in this context, is that `set_transient( '...', true, * MINUTE_IN_SECONDS );` will **not** run/re-evaluate every minute. Instead it will run/re-evaluate when the page has loaded by a visitor/user, and the data ther...
294,975
<p>It is in Wordpress, Divi. It seemed to me a simple task but somehow I haven't managed to get the proper result spending tons of hours with coding and testing. Currently I'm working on a website, where there are posts and I intend to give the possibility the user to jump to the adjacent posts with a simple link point...
[ { "answer_id": 294977, "author": "phatskat", "author_id": 20143, "author_profile": "https://wordpress.stackexchange.com/users/20143", "pm_score": 3, "selected": true, "text": "<p><strong>Warning Edit</strong>: Mark Kaplun's answer brings up a very good point - this will modify your conte...
2018/02/23
[ "https://wordpress.stackexchange.com/questions/294975", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137445/" ]
It is in Wordpress, Divi. It seemed to me a simple task but somehow I haven't managed to get the proper result spending tons of hours with coding and testing. Currently I'm working on a website, where there are posts and I intend to give the possibility the user to jump to the adjacent posts with a simple link pointing...
**Warning Edit**: Mark Kaplun's answer brings up a very good point - this will modify your content in unexpected ways. Say, for instance, you have another application that reads this post content from the WordPress API - that content will also have these links which is probably not what you want. You should really be a...
295,022
<p>I have created custom post type and created the post in a front custom form using logged in user and set status 'pending'. Now I want to show my created post preview like the published post.</p> <p>I have hit URL like admin <a href="http://localhost/project/?post_type=deals&amp;p=3305" rel="nofollow noreferrer">htt...
[ { "answer_id": 294977, "author": "phatskat", "author_id": 20143, "author_profile": "https://wordpress.stackexchange.com/users/20143", "pm_score": 3, "selected": true, "text": "<p><strong>Warning Edit</strong>: Mark Kaplun's answer brings up a very good point - this will modify your conte...
2018/02/24
[ "https://wordpress.stackexchange.com/questions/295022", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137451/" ]
I have created custom post type and created the post in a front custom form using logged in user and set status 'pending'. Now I want to show my created post preview like the published post. I have hit URL like admin <http://localhost/project/?post_type=deals&p=3305> but it is working for admin, not for author user. ...
**Warning Edit**: Mark Kaplun's answer brings up a very good point - this will modify your content in unexpected ways. Say, for instance, you have another application that reads this post content from the WordPress API - that content will also have these links which is probably not what you want. You should really be a...
295,043
<p>If I enqueue styles from my plugin, then it loads after theme's styles. That's why some CSS of my plugin is overriding by theme's CSS. This problem would be fixed if I can ensure my plugin's styles load after theme's styles.</p>
[ { "answer_id": 295046, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 0, "selected": false, "text": "<p>No. (or technically there might be, but in a few days there will be a question here about how to enqueue ...
2018/02/24
[ "https://wordpress.stackexchange.com/questions/295043", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/75264/" ]
If I enqueue styles from my plugin, then it loads after theme's styles. That's why some CSS of my plugin is overriding by theme's CSS. This problem would be fixed if I can ensure my plugin's styles load after theme's styles.
It's easy to add your plugin stylesheet after theme stylesheet. If you're sure that your theme styles and plugin styles have the same selector weight (*theme has this style `.site-header { background-color: #ccc; }` and your plugin has this `.site-header { background-color: #f1f1f1; }`*) then enqueuing plugin styleshee...
295,078
<p>I created a shortcode for user submission form. I want to submit this form without loading the page (Ajax).</p> <p>Here is my shortcode code</p> <pre><code>add_shortcode('et-test-plugin_shortcode', function($atts, $content) { $atts = shortcode_atts(array( 'name-field' =&gt; 'Name', 'phone-fiel...
[ { "answer_id": 295046, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 0, "selected": false, "text": "<p>No. (or technically there might be, but in a few days there will be a question here about how to enqueue ...
2018/02/24
[ "https://wordpress.stackexchange.com/questions/295078", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/75264/" ]
I created a shortcode for user submission form. I want to submit this form without loading the page (Ajax). Here is my shortcode code ``` add_shortcode('et-test-plugin_shortcode', function($atts, $content) { $atts = shortcode_atts(array( 'name-field' => 'Name', 'phone-field' => 'Phone Number', ...
It's easy to add your plugin stylesheet after theme stylesheet. If you're sure that your theme styles and plugin styles have the same selector weight (*theme has this style `.site-header { background-color: #ccc; }` and your plugin has this `.site-header { background-color: #f1f1f1; }`*) then enqueuing plugin styleshee...
295,086
<p>I am validating plugin to make it compatible with <code>WPCS</code>. a function which contains <code>gettext</code> placeholder returning error when i run <code>phpcs</code> command. Source code and screenshot of error is attached for reference. Maybe i am missing something or doing it in wrong way?</p> <pre><code>...
[ { "answer_id": 295046, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 0, "selected": false, "text": "<p>No. (or technically there might be, but in a few days there will be a question here about how to enqueue ...
2018/02/24
[ "https://wordpress.stackexchange.com/questions/295086", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/83820/" ]
I am validating plugin to make it compatible with `WPCS`. a function which contains `gettext` placeholder returning error when i run `phpcs` command. Source code and screenshot of error is attached for reference. Maybe i am missing something or doing it in wrong way? ``` /** * Add Error. * * @package Mypackage * @...
It's easy to add your plugin stylesheet after theme stylesheet. If you're sure that your theme styles and plugin styles have the same selector weight (*theme has this style `.site-header { background-color: #ccc; }` and your plugin has this `.site-header { background-color: #f1f1f1; }`*) then enqueuing plugin styleshee...
295,096
<p>I'm looking to hide from search a few custom post type posts. I'm thinking that if I create a custom taxonomy for the custom post type with a term "hidden" then all posts checked will be hidden. Maybe some filter that I can add to the functions file? By chance has anyone done this or something similar? Please advise...
[ { "answer_id": 295097, "author": "David Sword", "author_id": 132362, "author_profile": "https://wordpress.stackexchange.com/users/132362", "pm_score": 2, "selected": false, "text": "<p><a href=\"https://codex.wordpress.org/Function_Reference/register_post_type\" rel=\"nofollow noreferrer...
2018/02/25
[ "https://wordpress.stackexchange.com/questions/295096", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/134826/" ]
I'm looking to hide from search a few custom post type posts. I'm thinking that if I create a custom taxonomy for the custom post type with a term "hidden" then all posts checked will be hidden. Maybe some filter that I can add to the functions file? By chance has anyone done this or something similar? Please advise, t...
[`register_post_type()`](https://codex.wordpress.org/Function_Reference/register_post_type) has a [argument](https://codex.wordpress.org/Function_Reference/register_post_type#Arguments) that you can set to specify which post types you want searched, thus excluded the undesired ones. This is the simplest method, just on...
295,109
<p>I am trying to add a meta box to the "page" post type, in which I succeeded. In my meta box I would like to display a dropdown with titles from an other custom post type (named "Albums"). I also succeeded in that, but once I select a specific album in the dropdown and save the page, it changes the page permalink to ...
[ { "answer_id": 295111, "author": "obiPlabon", "author_id": 135737, "author_profile": "https://wordpress.stackexchange.com/users/135737", "pm_score": 2, "selected": true, "text": "<p>Here's the updated meta box callback function. I've used <code>get_posts()</code> instead of <code>WP_Quer...
2018/02/25
[ "https://wordpress.stackexchange.com/questions/295109", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137519/" ]
I am trying to add a meta box to the "page" post type, in which I succeeded. In my meta box I would like to display a dropdown with titles from an other custom post type (named "Albums"). I also succeeded in that, but once I select a specific album in the dropdown and save the page, it changes the page permalink to the...
Here's the updated meta box callback function. I've used `get_posts()` instead of `WP_Query` as `get_posts()` is more performant as well as easy to use in this case. And removed `get_post_custom()` as it'll fetch all the custom metadata when you don't need them. So, I've replaced that with `get_post_meta()`. Hope your ...
295,152
<p>I'm trying to change the default 10-day expiration for the cookie that allows a user to repeatedly view the content on a password-protected WP page without having to re-enter the page password during the default 10-day period. Rather than 10 days, I'd like to re-set the expiration to 30 seconds.</p> <p>The WP code ...
[ { "answer_id": 295135, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 1, "selected": false, "text": "<p>There is no reason for your design, but the core of your problem is that (I assume) people are trying to ...
2018/02/25
[ "https://wordpress.stackexchange.com/questions/295152", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137545/" ]
I'm trying to change the default 10-day expiration for the cookie that allows a user to repeatedly view the content on a password-protected WP page without having to re-enter the page password during the default 10-day period. Rather than 10 days, I'd like to re-set the expiration to 30 seconds. The WP code reference ...
There is no reason for your design, but the core of your problem is that (I assume) people are trying to use a free tier of the API instead of properly paying for its use and removing the ridiculous restrictions. Anyway, the solution is fairly simple, run your cron every half an hour, allocate to your import process u...
295,189
<p>I know this has been asked and answered before but the solutions are not working for my so I was wondering if something has changed or if I am doing something wrong. Want to display my Categories, Child Cats, Grand Child-Cats. This is my code:</p> <pre><code>function list_areas () { $provincearg = array( ...
[ { "answer_id": 295135, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 1, "selected": false, "text": "<p>There is no reason for your design, but the core of your problem is that (I assume) people are trying to ...
2018/02/26
[ "https://wordpress.stackexchange.com/questions/295189", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/107025/" ]
I know this has been asked and answered before but the solutions are not working for my so I was wondering if something has changed or if I am doing something wrong. Want to display my Categories, Child Cats, Grand Child-Cats. This is my code: ``` function list_areas () { $provincearg = array( ...
There is no reason for your design, but the core of your problem is that (I assume) people are trying to use a free tier of the API instead of properly paying for its use and removing the ridiculous restrictions. Anyway, the solution is fairly simple, run your cron every half an hour, allocate to your import process u...
295,221
<p>I have this code that pulls a user's gravatar:</p> <pre><code>if( $current_user-&gt;ID == 0 ) { // Not logged in. echo '&lt;p&gt;&lt;img src="'.get_stylesheet_directory_uri().'/img/wpb-default-gravatar.png" alt="תמונת פרופיל"&gt;&lt;/p&gt;'; echo '&lt;p&gt;רוצה למכור?&lt;/p&gt;'; echo '&lt;p&gt;&lt;...
[ { "answer_id": 295224, "author": "WebElaine", "author_id": 102815, "author_profile": "https://wordpress.stackexchange.com/users/102815", "pm_score": 1, "selected": false, "text": "<p>As the filename suggests, it's a default for when someone does not have a gravatar assigned. It is set up...
2018/02/26
[ "https://wordpress.stackexchange.com/questions/295221", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/84049/" ]
I have this code that pulls a user's gravatar: ``` if( $current_user->ID == 0 ) { // Not logged in. echo '<p><img src="'.get_stylesheet_directory_uri().'/img/wpb-default-gravatar.png" alt="תמונת פרופיל"></p>'; echo '<p>רוצה למכור?</p>'; echo '<p><a href="חשבון-חנות">פתח חנות</a></p>'; } else { $cur...
As the filename suggests, it's a default for when someone does not have a gravatar assigned. It is set up in your child theme and looks to be improperly set. You should search through the child theme files to find 'wpb-default-gravatar.png' and from there figure out what is adding the extra domain. If this is a child ...
295,234
<p>I'm relatively new to creating a theme with WordPress, and I've been adding all the stylesheets (main and for each page) with the old <code>echo get_stylesheet_uri();</code>. But I find out that this isn't the recommended way to do, and instead, to add all the styles within functions.php.</p> <p>Old method (working...
[ { "answer_id": 295239, "author": "maheshwaghmare", "author_id": 52167, "author_profile": "https://wordpress.stackexchange.com/users/52167", "pm_score": 0, "selected": false, "text": "<p>Use </p>\n\n<pre><code>wp_enqueue_style( 'theme-slug', get_stylesheet_uri() );\n</code></pre>\n\n<p>Bu...
2018/02/26
[ "https://wordpress.stackexchange.com/questions/295234", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/130486/" ]
I'm relatively new to creating a theme with WordPress, and I've been adding all the stylesheets (main and for each page) with the old `echo get_stylesheet_uri();`. But I find out that this isn't the recommended way to do, and instead, to add all the styles within functions.php. Old method (working): ``` <link rel="st...
Before adding any file you must seperate your `header.php` file & add `wp_head()` function in `header.php` file ``` // Load the theme stylesheets function theme_styles() { // Example of loading a custom css file for homepage just on the homepage wp_register_style( 'custom', get_template_...
295,247
<p>How would I change every post so that they had the same, hard-coded featured image?! Say this cigar:</p> <p><a href="https://www.cigarsofcuba.co.uk/acatalog/slide1.jpeg" rel="nofollow noreferrer">https://www.cigarsofcuba.co.uk/acatalog/slide1.jpeg</a></p> <p>(I don't actually want to do this - but it's a stumbling...
[ { "answer_id": 295253, "author": "Dave Romsey", "author_id": 2807, "author_profile": "https://wordpress.stackexchange.com/users/2807", "pm_score": 2, "selected": false, "text": "<p><strong>Method 1: Using the <code>publish_post</code> hook* and <code>media_sideload_image()</code></strong...
2018/02/26
[ "https://wordpress.stackexchange.com/questions/295247", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/121694/" ]
How would I change every post so that they had the same, hard-coded featured image?! Say this cigar: <https://www.cigarsofcuba.co.uk/acatalog/slide1.jpeg> (I don't actually want to do this - but it's a stumbling block in something more complex.) I think it ought to be this: ``` function set_post_thumbnail( $post, ...
**Method 1: Using the `publish_post` hook\* and `media_sideload_image()`** Here we will upload an image from a URL, attach it to the post, and set it as the featured image when the post is published. \*Actually, we're using the dynamic hook `{$new_status}_{$post->post_type}`, which refers transitioning a `post` post...
295,284
<p>I'm building a custom theme using Xampp on my localhost. I've got everything sorted for the site, except for this permalinks issue.</p> <p>Currently, the site uses the Advanced Custom Fields plugin and has some dependencies on this plugin to work.</p> <p>When using plain permalinks, the site works fine. When I cha...
[ { "answer_id": 295281, "author": "Morgan Estes", "author_id": 26317, "author_profile": "https://wordpress.stackexchange.com/users/26317", "pm_score": 1, "selected": false, "text": "<p>The <a href=\"https://developer.wordpress.org/plugins/javascript/ajax/\" rel=\"nofollow noreferrer\">Wor...
2018/02/27
[ "https://wordpress.stackexchange.com/questions/295284", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/108080/" ]
I'm building a custom theme using Xampp on my localhost. I've got everything sorted for the site, except for this permalinks issue. Currently, the site uses the Advanced Custom Fields plugin and has some dependencies on this plugin to work. When using plain permalinks, the site works fine. When I change to "Post name...
The [WordPress Plugin Developer Handbook](https://developer.wordpress.org/plugins/javascript/ajax/) has background info and code samples of how to use Ajax in your plugin (and themes). Give it a read and it should get you on the right path.
295,287
<p>I have a custom code in sidebar.php that shows all my categories and number of posts+custom posts. The code is working fine but, since I copied/pasted and modified various other codes from stackexchange forum, I am wondering how efficient the code is. </p> <p>I don't have any background on php, but at least I can t...
[ { "answer_id": 295281, "author": "Morgan Estes", "author_id": 26317, "author_profile": "https://wordpress.stackexchange.com/users/26317", "pm_score": 1, "selected": false, "text": "<p>The <a href=\"https://developer.wordpress.org/plugins/javascript/ajax/\" rel=\"nofollow noreferrer\">Wor...
2018/02/27
[ "https://wordpress.stackexchange.com/questions/295287", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137618/" ]
I have a custom code in sidebar.php that shows all my categories and number of posts+custom posts. The code is working fine but, since I copied/pasted and modified various other codes from stackexchange forum, I am wondering how efficient the code is. I don't have any background on php, but at least I can tell the be...
The [WordPress Plugin Developer Handbook](https://developer.wordpress.org/plugins/javascript/ajax/) has background info and code samples of how to use Ajax in your plugin (and themes). Give it a read and it should get you on the right path.
295,301
<p>I have successfully hidden my plugin from the plugins page using <code>$wp_list_table</code> however the pagination at the top still lists plugins as 'All (3)' etc.</p> <p>I managed to successfully alter the <code>$wp_list_table</code> array of <code>_pagination_args = total_items</code>.</p> <p>But it was still ...
[ { "answer_id": 295309, "author": "bueltge", "author_id": 170, "author_profile": "https://wordpress.stackexchange.com/users/170", "pm_score": 1, "selected": false, "text": "<p>The values haven't any hook to change this. However it is easy to identify the counter via Javascript. You can ch...
2018/02/27
[ "https://wordpress.stackexchange.com/questions/295301", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137624/" ]
I have successfully hidden my plugin from the plugins page using `$wp_list_table` however the pagination at the top still lists plugins as 'All (3)' etc. I managed to successfully alter the `$wp_list_table` array of `_pagination_args = total_items`. But it was still rendering Plugins - 'All (3)' at the top of the pag...
The values haven't any hook to change this. However it is easy to identify the counter via Javascript. You can change this with short lines of Javascript. Hook ---- You should hook in this page hook of the plugin page `admin_footer-plugins.php`, like `add_action( 'admin_footer-plugins.php', [ $this, 'change_view_valu...
295,315
<p>So I want to have a normal menu on the home page but on the other pages, I want "hamburger" menus! I've searched for a plugin but all of the menu plugins were more like to edit the mobile menu or had an absolute different purpose.So my question is does anyone have a solution for this?</p>
[ { "answer_id": 295317, "author": "Beee", "author_id": 103402, "author_profile": "https://wordpress.stackexchange.com/users/103402", "pm_score": 0, "selected": false, "text": "<p>The easiest would be to serve 2 different menus and assign them different css classes, so you can style them d...
2018/02/27
[ "https://wordpress.stackexchange.com/questions/295315", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137633/" ]
So I want to have a normal menu on the home page but on the other pages, I want "hamburger" menus! I've searched for a plugin but all of the menu plugins were more like to edit the mobile menu or had an absolute different purpose.So my question is does anyone have a solution for this?
The easiest would be to serve 2 different menus and assign them different css classes, so you can style them differently. ``` if ( is_home() ) { // use home menu wp_nav_menu( array( 'menu' => 'home', 'menu_class' => 'menu_home' ); } else { // use other menu wp_nav_menu( array( 'menu' => 'nohome', 'menu...
295,367
<p>I have created a custom taxonomy for my posts called "Regions." And I have tagged 2 posts with these regions. What I would like to do is list out any post that is tagged with a region, but for some reason it's not working. Here's my function to register the custom taxonomy:</p> <pre><code>function region_taxonomy()...
[ { "answer_id": 295370, "author": "user13286", "author_id": 13286, "author_profile": "https://wordpress.stackexchange.com/users/13286", "pm_score": 0, "selected": false, "text": "<p>Apparently only specifying the <code>taxonomy</code> is not enough, I was able to solve my issue like this:...
2018/02/27
[ "https://wordpress.stackexchange.com/questions/295367", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13286/" ]
I have created a custom taxonomy for my posts called "Regions." And I have tagged 2 posts with these regions. What I would like to do is list out any post that is tagged with a region, but for some reason it's not working. Here's my function to register the custom taxonomy: ``` function region_taxonomy() { $label...
Taxonomy query doesn't work without `terms` parameter. So you have to first query all the **regions** term then assign term ids to taxonomy query. Here's the solution - ``` $terms = get_terms( array( 'taxonomy' => 'regions', 'fields' => 'id=>slug', ) ); $args = array( 'orderby' => 'date', ...
295,373
<p>I am using WordPress's default Gallery and adding categories to them. I now created a shortcode with a loop to get the Galleries to a page:</p> <pre><code>if(! function_exists('test_shortcode')){ function lv_gallery_style_one_shortcode($atts, $content = null){ extract(shortcode_atts( array( 'title'=&gt;...
[ { "answer_id": 295370, "author": "user13286", "author_id": 13286, "author_profile": "https://wordpress.stackexchange.com/users/13286", "pm_score": 0, "selected": false, "text": "<p>Apparently only specifying the <code>taxonomy</code> is not enough, I was able to solve my issue like this:...
2018/02/27
[ "https://wordpress.stackexchange.com/questions/295373", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/71410/" ]
I am using WordPress's default Gallery and adding categories to them. I now created a shortcode with a loop to get the Galleries to a page: ``` if(! function_exists('test_shortcode')){ function lv_gallery_style_one_shortcode($atts, $content = null){ extract(shortcode_atts( array( 'title'=>'', ), $a...
Taxonomy query doesn't work without `terms` parameter. So you have to first query all the **regions** term then assign term ids to taxonomy query. Here's the solution - ``` $terms = get_terms( array( 'taxonomy' => 'regions', 'fields' => 'id=>slug', ) ); $args = array( 'orderby' => 'date', ...
295,405
<p>I have created a custom Plugin, and wanted to hide its shortcode <code>[related]</code> from the content once the plugin is deactivated. Everything is working fine, but when i deactivate the plugin the stray shortcode is still there. and i dont want to install any other plugin to hide that.</p> <pre><code>register_...
[ { "answer_id": 295410, "author": "Iceable", "author_id": 136263, "author_profile": "https://wordpress.stackexchange.com/users/136263", "pm_score": 2, "selected": false, "text": "<p>I'm afraid hiding the shortcode once the plugin is deactivated is simply not possible.</p>\n\n<p>The only w...
2018/02/28
[ "https://wordpress.stackexchange.com/questions/295405", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/126760/" ]
I have created a custom Plugin, and wanted to hide its shortcode `[related]` from the content once the plugin is deactivated. Everything is working fine, but when i deactivate the plugin the stray shortcode is still there. and i dont want to install any other plugin to hide that. ``` register_deactivation_hook( __FILE...
I'm afraid hiding the shortcode once the plugin is deactivated is simply not possible. The only way to "hide" a shortcode from the content is to register the shortcode with a calback that returns nothing, as in: ``` add_shortcode( 'related', function(){ return null; } ); ``` But of course you cannot do that without...
295,413
<p>I have developed a WordPress Website. It's on the live server but in development mode.I want if someone to visit my website. It should ask for password or access token to before loading site.</p> <p>Is there a way to achieve this functionality. </p> <p>Note: I have put my code in the answer that's working. Please ...
[ { "answer_id": 295410, "author": "Iceable", "author_id": 136263, "author_profile": "https://wordpress.stackexchange.com/users/136263", "pm_score": 2, "selected": false, "text": "<p>I'm afraid hiding the shortcode once the plugin is deactivated is simply not possible.</p>\n\n<p>The only w...
2018/02/28
[ "https://wordpress.stackexchange.com/questions/295413", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137328/" ]
I have developed a WordPress Website. It's on the live server but in development mode.I want if someone to visit my website. It should ask for password or access token to before loading site. Is there a way to achieve this functionality. Note: I have put my code in the answer that's working. Please review it. Is thi...
I'm afraid hiding the shortcode once the plugin is deactivated is simply not possible. The only way to "hide" a shortcode from the content is to register the shortcode with a calback that returns nothing, as in: ``` add_shortcode( 'related', function(){ return null; } ); ``` But of course you cannot do that without...
295,415
<p>I would like to change the output of posts_nav_link(); ( Or be pointed in a new direction, that's fine by me ) What i want to do is show &lt; Previous archivepage| Next archivepage > even if there is no previous or next page, currently it removed whichever link isn't in use, i would like it to still show the t...
[ { "answer_id": 295423, "author": "Jacob Peattie", "author_id": 39152, "author_profile": "https://wordpress.stackexchange.com/users/39152", "pm_score": 2, "selected": true, "text": "<p><code>posts_nav_link()</code> just outputs <code>get_previous_posts_link()</code> and <code>get_next_pos...
2018/02/28
[ "https://wordpress.stackexchange.com/questions/295415", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/108736/" ]
I would like to change the output of posts\_nav\_link(); ( Or be pointed in a new direction, that's fine by me ) What i want to do is show < Previous archivepage| Next archivepage > even if there is no previous or next page, currently it removed whichever link isn't in use, i would like it to still show the text < pre...
`posts_nav_link()` just outputs `get_previous_posts_link()` and `get_next_posts_link()` with a separator between them. The helpful thing is does is handle the visibility of the separator depending on whether both pages exist. Since you always want to show something on either side, you don't need it. What you can do is ...
295,419
<p>I tried to place HTML code in WordPress menu description, it's showing an inline code <code>&lt;i class="fa fa-cloud"&gt;&lt;/i&gt;</code> instead of an icon.</p> <p>Already tried that one but still not working</p> <pre><code>// Allow HTML descriptions in WordPress Menu remove_filter( 'nav_menu_description', 'stri...
[ { "answer_id": 295422, "author": "Md. Amanur Rahman", "author_id": 109213, "author_profile": "https://wordpress.stackexchange.com/users/109213", "pm_score": -1, "selected": true, "text": "<p>Put the below full code and that should work..</p>\n\n<pre><code>&lt;?php class Description_Walke...
2018/02/28
[ "https://wordpress.stackexchange.com/questions/295419", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/24762/" ]
I tried to place HTML code in WordPress menu description, it's showing an inline code `<i class="fa fa-cloud"></i>` instead of an icon. Already tried that one but still not working ``` // Allow HTML descriptions in WordPress Menu remove_filter( 'nav_menu_description', 'strip_tags' ); add_filter( 'wp_setup_nav_menu_it...
Put the below full code and that should work.. ``` <?php class Description_Walker extends Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { $classes = empty ( $item->classes ) ? array () : (array) $item->classes; $class_names = join( ' ' , apply_f...
295,436
<p>I would like to check a posts status, in particular I want to know if a post is set to draft or is privately published.</p> <p>I have the following code:</p> <pre><code> if ('draft' != get_post_status() || is_user_logged_in()) { $this-&gt;render(); } else { wp_redirect( site_url('404') )...
[ { "answer_id": 295437, "author": "Christine Cooper", "author_id": 24875, "author_profile": "https://wordpress.stackexchange.com/users/24875", "pm_score": 4, "selected": true, "text": "<p>To check post with post status <code>private</code>, you could run the following:</p>\n\n<pre><code>i...
2018/02/28
[ "https://wordpress.stackexchange.com/questions/295436", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/38592/" ]
I would like to check a posts status, in particular I want to know if a post is set to draft or is privately published. I have the following code: ``` if ('draft' != get_post_status() || is_user_logged_in()) { $this->render(); } else { wp_redirect( site_url('404') ); exit; } `...
To check post with post status `private`, you could run the following: ``` if (get_post_status() == 'private' && is_user_logged_in()) { // it's private and user is logged in, do stuff } elseif (get_post_status() == 'draft') { // it's draft, do stuff } else { // it's something else, do stuff } ``` Or,...
295,471
<p><strong>For those that arrive from Google: You <a href="https://github.com/WP-API/docs/pull/20#issuecomment-370286436" rel="noreferrer">probably shouldn't get the nonces from the REST API</a>, unless you <em>really</em> know what you're doing. Cookie-based authentication with the REST API is only <em>meant</em> for ...
[ { "answer_id": 295538, "author": "Christian", "author_id": 78685, "author_profile": "https://wordpress.stackexchange.com/users/78685", "pm_score": 1, "selected": false, "text": "<p>While this solution works, <a href=\"https://github.com/WP-API/docs/pull/20#issuecomment-370286436\" rel=\"...
2018/02/28
[ "https://wordpress.stackexchange.com/questions/295471", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/78685/" ]
**For those that arrive from Google: You [probably shouldn't get the nonces from the REST API](https://github.com/WP-API/docs/pull/20#issuecomment-370286436), unless you *really* know what you're doing. Cookie-based authentication with the REST API is only *meant* for plugins and themes. For a single page application, ...
Take a closer look at the `function rest_cookie_check_errors()`. When you get the nonce via `/wp-json/nonce/v1/get`, you're not sending a nonce in the first place. So this function nullifies your authentication, with this code: ``` if ( null === $nonce ) { // No nonce at all, so act as if it's an unauthenticated ...
295,489
<p>I've got a wordpress site using MAMP on localhost. Everything's running fine, right up until I try to modify the menu. The menu has about 34 items on it, mostly pages, with a few custom links (placeholders for pages I haven't made yet).</p> <p>When I try to save the menu after modifying it (Adding another page, or ...
[ { "answer_id": 296058, "author": "bueltge", "author_id": 170, "author_profile": "https://wordpress.stackexchange.com/users/170", "pm_score": 0, "selected": false, "text": "<p>I don't have any solution for your problem. At first I thought also on the php value for <code>max_input_vars</co...
2018/02/28
[ "https://wordpress.stackexchange.com/questions/295489", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/92192/" ]
I've got a wordpress site using MAMP on localhost. Everything's running fine, right up until I try to modify the menu. The menu has about 34 items on it, mostly pages, with a few custom links (placeholders for pages I haven't made yet). When I try to save the menu after modifying it (Adding another page, or a custom l...
Obviously, this is non standard WP behaviour, so tons of things could be wrong, but there are some ways to track down the error. The most important thing, I think, is the fact that storing the menu through the customizer works. This means that the function which does the storing of single menu items [`wp_update_nav_men...
295,511
<p>I have a simple endpoint. Its GET, I pass it an ID parameter and it uses this ID to make a curl call. The endpoint then responds with a couple pieces of info json_encoded.</p> <p>The issue is that this endpoint keeps caching its results. How do I keep this from happening?</p> <p>Couple notes:</p> <ol> <li>No c...
[ { "answer_id": 314521, "author": "SungamR", "author_id": 150837, "author_profile": "https://wordpress.stackexchange.com/users/150837", "pm_score": 2, "selected": false, "text": "<p>If you have access to your request header you can add the line.\n<code>Cache-Control: private</code> or <co...
2018/03/01
[ "https://wordpress.stackexchange.com/questions/295511", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/5181/" ]
I have a simple endpoint. Its GET, I pass it an ID parameter and it uses this ID to make a curl call. The endpoint then responds with a couple pieces of info json\_encoded. The issue is that this endpoint keeps caching its results. How do I keep this from happening? Couple notes: 1. No caching plugins installed 2. W...
If you have access to your request header you can add the line. `Cache-Control: private` or `Cache-Control: no-cache`. This will force well-behaved hosts to send you fresh results.
295,558
<p>I intend to programmatically create a widget area for each product category within WooCommerce.</p> <p>I currently have the following code in my <code>functions.php</code>:</p> <pre><code>function add_widget_areas() { $args = array( 'taxonomy' =&gt; 'product_cat', 'hide_empty' =&gt; false, ...
[ { "answer_id": 295545, "author": "Atif Aqeel", "author_id": 136891, "author_profile": "https://wordpress.stackexchange.com/users/136891", "pm_score": 1, "selected": false, "text": "<p>this is shortcode this coming from the sidebar, go to appearance -> widget. select the sidebar and remov...
2018/03/01
[ "https://wordpress.stackexchange.com/questions/295558", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137798/" ]
I intend to programmatically create a widget area for each product category within WooCommerce. I currently have the following code in my `functions.php`: ``` function add_widget_areas() { $args = array( 'taxonomy' => 'product_cat', 'hide_empty' => false, 'parent' => 0, ); $p...
This is a shortcode of the [Popup builder plugin](https://wordpress.org/plugins/popup-builder/) that for some reason is not being evaluated. Is that plugin installed? Most likely the shortcode is in a widget somewhere. It could also be in a theme file.
295,570
<p>i have script which displays iframe after certain seconds.</p> <pre><code>&lt;script type="text/javascript"&gt;//&lt;![CDATA[ $(window).load(function(){ setTimeout(function(){ $(".hidden_div").show(function(){ $(this).find("iframe").prop("src", function(){ return $(this).data("src"); }); }); }, 5000); });//]]&gt; ...
[ { "answer_id": 295573, "author": "Xhynk", "author_id": 13724, "author_profile": "https://wordpress.stackexchange.com/users/13724", "pm_score": 2, "selected": true, "text": "<p>If you only have one iframe, just set the iframe's <code>src</code> attribute in the <code>.show()</code> callba...
2018/03/01
[ "https://wordpress.stackexchange.com/questions/295570", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/86147/" ]
i have script which displays iframe after certain seconds. ``` <script type="text/javascript">//<![CDATA[ $(window).load(function(){ setTimeout(function(){ $(".hidden_div").show(function(){ $(this).find("iframe").prop("src", function(){ return $(this).data("src"); }); }); }, 5000); });//]]> </script> ``` But it wor...
If you only have one iframe, just set the iframe's `src` attribute in the `.show()` callback function. ``` <script type="text/javascript">//<![CDATA[ jQuery(window).load(function($){ setTimeout(function(){ $('.hidden_div').show(function(){ $(this).find('iframe').attr('src', 'htt...
295,596
<p>i want to auto add custom field value when post publish , my custom fields name is "quality" and the value is "HD" .</p> <p>i've look through this site and apparently codes i found is not working. so far i've tried this code :</p> <pre><code>/* Do something with the data entered */ add_action( 'save_post', 'myplu...
[ { "answer_id": 295573, "author": "Xhynk", "author_id": 13724, "author_profile": "https://wordpress.stackexchange.com/users/13724", "pm_score": 2, "selected": true, "text": "<p>If you only have one iframe, just set the iframe's <code>src</code> attribute in the <code>.show()</code> callba...
2018/03/02
[ "https://wordpress.stackexchange.com/questions/295596", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/136816/" ]
i want to auto add custom field value when post publish , my custom fields name is "quality" and the value is "HD" . i've look through this site and apparently codes i found is not working. so far i've tried this code : ``` /* Do something with the data entered */ add_action( 'save_post', 'myplugin_save_postdata' );...
If you only have one iframe, just set the iframe's `src` attribute in the `.show()` callback function. ``` <script type="text/javascript">//<![CDATA[ jQuery(window).load(function($){ setTimeout(function(){ $('.hidden_div').show(function(){ $(this).find('iframe').attr('src', 'htt...
295,617
<p>I understand <em>how</em> to use <code>get_post_metadata()</code>, however this code in a custom RSS feed template:</p> <pre><code>while( have_posts()) : the_post(); // Has a custom URL been supplied? Use that in preference. $feature_permalink = ‌‌get_post_meta(get_the_ID(), '_featureurl', true); [......
[ { "answer_id": 295750, "author": "Dave Romsey", "author_id": 2807, "author_profile": "https://wordpress.stackexchange.com/users/2807", "pm_score": 1, "selected": false, "text": "<p>To modify an RSS item's <code>&lt;link&gt;</code> node value, use the <code>the_permalink_rss</code> filter...
2018/03/02
[ "https://wordpress.stackexchange.com/questions/295617", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/42868/" ]
I understand *how* to use `get_post_metadata()`, however this code in a custom RSS feed template: ``` while( have_posts()) : the_post(); // Has a custom URL been supplied? Use that in preference. $feature_permalink = ‌‌get_post_meta(get_the_ID(), '_featureurl', true); [...] ``` is giving: > > HP Fata...
This is a workaround, but it did solve things for me. First I moved this site from my vvv to vvv2 dev environment, to rule out anything odd there. Then I went through the WP config files and the rest of functions.php carefully looking for anything with the potential to break things. No luck so far. I traced *get\_p...
295,630
<p>I've a custom Post Type i.e. <code>prj</code> and need to auto increment it's <code>post_title</code> (title) and <code>post_name</code> (slug) on post save, update regardless of the post status .. the post can never be deleted that's why it won't be an issue ..</p> <p>Need it to behave just like AutoIncrement fiel...
[ { "answer_id": 295750, "author": "Dave Romsey", "author_id": 2807, "author_profile": "https://wordpress.stackexchange.com/users/2807", "pm_score": 1, "selected": false, "text": "<p>To modify an RSS item's <code>&lt;link&gt;</code> node value, use the <code>the_permalink_rss</code> filter...
2018/03/02
[ "https://wordpress.stackexchange.com/questions/295630", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/58627/" ]
I've a custom Post Type i.e. `prj` and need to auto increment it's `post_title` (title) and `post_name` (slug) on post save, update regardless of the post status .. the post can never be deleted that's why it won't be an issue .. Need it to behave just like AutoIncrement field in SQL .. once an ID is assigned, it shou...
This is a workaround, but it did solve things for me. First I moved this site from my vvv to vvv2 dev environment, to rule out anything odd there. Then I went through the WP config files and the rest of functions.php carefully looking for anything with the potential to break things. No luck so far. I traced *get\_p...
295,641
<pre><code>&lt;title&gt; &lt;?php if ( is_single() ) { single_post_title('', true); } else { bloginfo('name'); echo " - "; bloginfo('description'); } ?&gt; &lt;/title&gt; </code></pre> <p>This is my title tag code used for my wordpress blog. But Seo analyst shows <code>No title...
[ { "answer_id": 295750, "author": "Dave Romsey", "author_id": 2807, "author_profile": "https://wordpress.stackexchange.com/users/2807", "pm_score": 1, "selected": false, "text": "<p>To modify an RSS item's <code>&lt;link&gt;</code> node value, use the <code>the_permalink_rss</code> filter...
2018/03/02
[ "https://wordpress.stackexchange.com/questions/295641", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137862/" ]
``` <title> <?php if ( is_single() ) { single_post_title('', true); } else { bloginfo('name'); echo " - "; bloginfo('description'); } ?> </title> ``` This is my title tag code used for my wordpress blog. But Seo analyst shows `No title tag` found error
This is a workaround, but it did solve things for me. First I moved this site from my vvv to vvv2 dev environment, to rule out anything odd there. Then I went through the WP config files and the rest of functions.php carefully looking for anything with the potential to break things. No luck so far. I traced *get\_p...
295,654
<p>I'm trying to find a way to not show all the terms of a taxonomy, but only the terms of the current displayed posts of the wp_query.</p> <p>The code below displays all terms for 'brands' taxonomy and the query displays all products of the current category, i want to display only the terms that are set on the produc...
[ { "answer_id": 295668, "author": "David Sword", "author_id": 132362, "author_profile": "https://wordpress.stackexchange.com/users/132362", "pm_score": 2, "selected": false, "text": "<p>You'd probably do something like this </p>\n\n<pre><code>$args = array(\n 'post_type' =&gt; 'product',...
2018/03/02
[ "https://wordpress.stackexchange.com/questions/295654", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/111513/" ]
I'm trying to find a way to not show all the terms of a taxonomy, but only the terms of the current displayed posts of the wp\_query. The code below displays all terms for 'brands' taxonomy and the query displays all products of the current category, i want to display only the terms that are set on the products that a...
You'd probably do something like this ``` $args = array( 'post_type' => 'product', 'product_cat' => get_queried_object() ); $query = new WP_Query( $args ); $termsInPosts = array(); if ( $query->have_posts() ) { while( $query->have_posts() ) : $query->the_post(); $postTerms = wp_get_post_terms(get_the...
295,693
<p>I want to get a list of products of a given category from WP_query, but it won't work like it should.</p> <p>I've done this :</p> <pre><code>$args = array( 'post_type' =&gt; 'product', 'product_cat' =&gt; 17, ); $products = new WP_Query($args); </code></pre> <p>But this returns <strong>every</strong> pro...
[ { "answer_id": 295668, "author": "David Sword", "author_id": 132362, "author_profile": "https://wordpress.stackexchange.com/users/132362", "pm_score": 2, "selected": false, "text": "<p>You'd probably do something like this </p>\n\n<pre><code>$args = array(\n 'post_type' =&gt; 'product',...
2018/03/03
[ "https://wordpress.stackexchange.com/questions/295693", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/112695/" ]
I want to get a list of products of a given category from WP\_query, but it won't work like it should. I've done this : ``` $args = array( 'post_type' => 'product', 'product_cat' => 17, ); $products = new WP_Query($args); ``` But this returns **every** product from my shop ... I have also tried with 'cat',...
You'd probably do something like this ``` $args = array( 'post_type' => 'product', 'product_cat' => get_queried_object() ); $query = new WP_Query( $args ); $termsInPosts = array(); if ( $query->have_posts() ) { while( $query->have_posts() ) : $query->the_post(); $postTerms = wp_get_post_terms(get_the...
295,714
<p>Is it possible to override single plugin translation in function.php file and how that can be done?</p>
[ { "answer_id": 295729, "author": "Dave Romsey", "author_id": 2807, "author_profile": "https://wordpress.stackexchange.com/users/2807", "pm_score": 3, "selected": false, "text": "<p>Here's an example where a string from a certain text domain is translated using the <code>gettext</code> fi...
2018/03/03
[ "https://wordpress.stackexchange.com/questions/295714", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/92020/" ]
Is it possible to override single plugin translation in function.php file and how that can be done?
Here's an example where a string from a certain text domain is translated using the `gettext` filter: ``` /** * Translate a certain string from a particular text domain. * * @param string $translation Translated text. * @param string $text Text to translate. * @param string $domain Text domain. Uni...
295,734
<p>the thing is that in mobile/tabler versions blank white space appears. In desktop version there is no such problem. Moreover, I noticed that if you drag something in mobile version from that blank space, it appears to be a logo from header. I would appreciate any help. My website: www.avizen.lt</p>
[ { "answer_id": 295729, "author": "Dave Romsey", "author_id": 2807, "author_profile": "https://wordpress.stackexchange.com/users/2807", "pm_score": 3, "selected": false, "text": "<p>Here's an example where a string from a certain text domain is translated using the <code>gettext</code> fi...
2018/03/04
[ "https://wordpress.stackexchange.com/questions/295734", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137935/" ]
the thing is that in mobile/tabler versions blank white space appears. In desktop version there is no such problem. Moreover, I noticed that if you drag something in mobile version from that blank space, it appears to be a logo from header. I would appreciate any help. My website: www.avizen.lt
Here's an example where a string from a certain text domain is translated using the `gettext` filter: ``` /** * Translate a certain string from a particular text domain. * * @param string $translation Translated text. * @param string $text Text to translate. * @param string $domain Text domain. Uni...
295,741
<p>I'm trying to display the get_category_category limiting the results to only the child categories of parent "666". </p> <p>So a post may have a number of categories e.g. "1234", "666", "666/1341", "5", "5/17" but I only want to show the child of "666".</p> <pre><code>$args = array( 'numberposts' =&gt; '5','post_st...
[ { "answer_id": 295742, "author": "admcfajn", "author_id": 123674, "author_profile": "https://wordpress.stackexchange.com/users/123674", "pm_score": 1, "selected": false, "text": "<p>You can do this by getting the child categories of that category first, then passing them as an array to y...
2018/03/04
[ "https://wordpress.stackexchange.com/questions/295741", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137938/" ]
I'm trying to display the get\_category\_category limiting the results to only the child categories of parent "666". So a post may have a number of categories e.g. "1234", "666", "666/1341", "5", "5/17" but I only want to show the child of "666". ``` $args = array( 'numberposts' => '5','post_status' => 'publish','ca...
You can do this by getting the child categories of that category first, then passing them as an array to your query. ``` $categories=get_categories( array( 'parent' => $cat->cat_ID ) ); $cat_list = []; foreach ($categories as $c) { $cat_list[] = $c->term_id; } ``` ref: [Get the children of the parent catego...
295,879
<p>I want to use this:</p> <pre><code>http://www.example.com/directory/alan-walker </code></pre> <p>instead of calling <code>alan-walker.php</code> (which is non-existent) it should call <code>directory.php?s=alan-walker</code></p> <p>Is this possible?</p> <p>I suspect it's the <code>.htaccess</code> rewrite no?</p...
[ { "answer_id": 295931, "author": "Ravi Patel", "author_id": 35477, "author_profile": "https://wordpress.stackexchange.com/users/35477", "pm_score": 0, "selected": false, "text": "<blockquote>\n <p><strong>Change the Search-URL of WordPress - Add code in function.php and customize with d...
2018/03/05
[ "https://wordpress.stackexchange.com/questions/295879", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137938/" ]
I want to use this: ``` http://www.example.com/directory/alan-walker ``` instead of calling `alan-walker.php` (which is non-existent) it should call `directory.php?s=alan-walker` Is this possible? I suspect it's the `.htaccess` rewrite no? Effectively what this does is it means I can use this: ``` /directory/ala...
I assume `alan-walker` is just an example and this could be any string of this form. (Or is it literally just "alan-walker", as in you example?) You can do this with a single `RewriteRule` in `.htaccess` *before* the WordPress front-controller. For example: ``` RewriteRule ^directory/([a-z-]+)$ /directory.php?s=$1 [L...
295,910
<p>I have put this code inside PHP file and put that file in root folder. When I run this file it Create "Admin" user for only main site. I want code that will create "super admin" which can access all the multi-site. </p> <pre><code>require ('wp-blog-header.php'); $newusername = 'USERNAME'; $newpassword = 'PASSWORD';...
[ { "answer_id": 295931, "author": "Ravi Patel", "author_id": 35477, "author_profile": "https://wordpress.stackexchange.com/users/35477", "pm_score": 0, "selected": false, "text": "<blockquote>\n <p><strong>Change the Search-URL of WordPress - Add code in function.php and customize with d...
2018/03/06
[ "https://wordpress.stackexchange.com/questions/295910", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110795/" ]
I have put this code inside PHP file and put that file in root folder. When I run this file it Create "Admin" user for only main site. I want code that will create "super admin" which can access all the multi-site. ``` require ('wp-blog-header.php'); $newusername = 'USERNAME'; $newpassword = 'PASSWORD'; $newemail = '...
I assume `alan-walker` is just an example and this could be any string of this form. (Or is it literally just "alan-walker", as in you example?) You can do this with a single `RewriteRule` in `.htaccess` *before* the WordPress front-controller. For example: ``` RewriteRule ^directory/([a-z-]+)$ /directory.php?s=$1 [L...
295,912
<p>Please note that, I'm not telling about conditionally enqueue/dequeue scripts, I'm referring to conditionally dequeue certain dependencies from an existing enqueued scripts in front end. And please note the question is not plugin-specific. I want to be enlightened about the general rules.</p> <p>I used Elementor (p...
[ { "answer_id": 295935, "author": "Dave Romsey", "author_id": 2807, "author_profile": "https://wordpress.stackexchange.com/users/2807", "pm_score": 3, "selected": true, "text": "<h2>Solution 1:</h2>\n\n<p>Here we will dequeue and deregister <code>elementor-dialog</code> <em>and</em> <code...
2018/03/06
[ "https://wordpress.stackexchange.com/questions/295912", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/22728/" ]
Please note that, I'm not telling about conditionally enqueue/dequeue scripts, I'm referring to conditionally dequeue certain dependencies from an existing enqueued scripts in front end. And please note the question is not plugin-specific. I want to be enlightened about the general rules. I used Elementor (page builde...
Solution 1: ----------- Here we will dequeue and deregister `elementor-dialog` *and* `elementor-frontend`, then we will re-register `elementor-frontend` without the `elementor-dialog` dependency: ``` // This needs to fire after priority 5 which is where Elementor // handles enqueueing scripts. We're ok since the defa...
295,919
<p>I need to add the same CSS class to <code>&lt;body&gt;</code> element of all translatons of a page, but the CSS class added with <code>body_class()</code> is different for each translation because it is taken from the translated title of the page.</p> <p>For example, for <em>about us</em> page I get this markup:</p...
[ { "answer_id": 295927, "author": "ZecKa", "author_id": 82323, "author_profile": "https://wordpress.stackexchange.com/users/82323", "pm_score": 3, "selected": true, "text": "<p>It's not a good practice to use post name to style your page. Maybe you can use template page.</p>\n\n<p>But if ...
2018/03/06
[ "https://wordpress.stackexchange.com/questions/295919", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/77722/" ]
I need to add the same CSS class to `<body>` element of all translatons of a page, but the CSS class added with `body_class()` is different for each translation because it is taken from the translated title of the page. For example, for *about us* page I get this markup: ``` <body class="about-us"> // English ...
It's not a good practice to use post name to style your page. Maybe you can use template page. But if you still want to do it, you can do something like this: ``` function add_default_language_slug_class( $classes ) { global $post; if ( isset( $post ) ) { $default_language = wpml_get_default_language(...
295,936
<p>i a have a woocommerce file "checkout-form.php". I want remove the following actions via functions.php</p> <pre><code>&lt;?php do_action( 'woocommerce_checkout_after_order_review' ); ?&gt; &lt;/form&gt; &lt;?php do_action( 'woocommerce_after_checkout_form', $checkout ); ?&gt; </code></pre> <p>I used the followin...
[ { "answer_id": 295939, "author": "Ravi Patel", "author_id": 35477, "author_profile": "https://wordpress.stackexchange.com/users/35477", "pm_score": 0, "selected": false, "text": "<p>You have remove specific action using remove_action.</p>\n\n<p>So you can find all actions related to this...
2018/03/06
[ "https://wordpress.stackexchange.com/questions/295936", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/82174/" ]
i a have a woocommerce file "checkout-form.php". I want remove the following actions via functions.php ``` <?php do_action( 'woocommerce_checkout_after_order_review' ); ?> </form> <?php do_action( 'woocommerce_after_checkout_form', $checkout ); ?> ``` I used the following code in the functions.php but nothing happ...
First of all, you have to understand how hooks or more specifically how action hooks work. We use [`add_action( $name, $callback )`](https://developer.wordpress.org/reference/functions/add_action/) to register an action hook which takes a name and a callback function as a required parameter. And we use [`do_action( $na...
295,940
<p>I am trying to modify a theme by its child theme. The author already create a child theme.</p> <p>I add many thing in the stylesheet, but it's not working. When I check in Developer mode. I see the link rel for stylesheet is <strong><em><a href="https://.../style.css?ver=494" rel="nofollow noreferrer">https://.../s...
[ { "answer_id": 295939, "author": "Ravi Patel", "author_id": 35477, "author_profile": "https://wordpress.stackexchange.com/users/35477", "pm_score": 0, "selected": false, "text": "<p>You have remove specific action using remove_action.</p>\n\n<p>So you can find all actions related to this...
2018/03/06
[ "https://wordpress.stackexchange.com/questions/295940", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/138087/" ]
I am trying to modify a theme by its child theme. The author already create a child theme. I add many thing in the stylesheet, but it's not working. When I check in Developer mode. I see the link rel for stylesheet is ***<https://.../style.css?ver=494>*** and **style.css?ver=494** is empty I think the functions.php ...
First of all, you have to understand how hooks or more specifically how action hooks work. We use [`add_action( $name, $callback )`](https://developer.wordpress.org/reference/functions/add_action/) to register an action hook which takes a name and a callback function as a required parameter. And we use [`do_action( $na...
295,959
<p>I have a plugin which I downloaded and removed alot off stuff I don't need from. I also renamed it for simplicity, but right now it is linked to some other plugin, close to the name I gave it. If I go to Plugins under WP-Admin I can press View details. And it brings me information about a plugin with the name I gave...
[ { "answer_id": 295939, "author": "Ravi Patel", "author_id": 35477, "author_profile": "https://wordpress.stackexchange.com/users/35477", "pm_score": 0, "selected": false, "text": "<p>You have remove specific action using remove_action.</p>\n\n<p>So you can find all actions related to this...
2018/03/06
[ "https://wordpress.stackexchange.com/questions/295959", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/138051/" ]
I have a plugin which I downloaded and removed alot off stuff I don't need from. I also renamed it for simplicity, but right now it is linked to some other plugin, close to the name I gave it. If I go to Plugins under WP-Admin I can press View details. And it brings me information about a plugin with the name I gave it...
First of all, you have to understand how hooks or more specifically how action hooks work. We use [`add_action( $name, $callback )`](https://developer.wordpress.org/reference/functions/add_action/) to register an action hook which takes a name and a callback function as a required parameter. And we use [`do_action( $na...
295,992
<p>I know that you can install plugin code as part of a theme, but I would like to do it the other way round. I'm developing a plugin that changes many aspects of WordPress and most will not be visible without my theme providing support for it. In other words it makes very little sense to run the plugin without the the...
[ { "answer_id": 295993, "author": "Sean", "author_id": 138112, "author_profile": "https://wordpress.stackexchange.com/users/138112", "pm_score": 0, "selected": false, "text": "<p>It looks like the function <a href=\"https://codex.wordpress.org/Function_Reference/register_theme_directory\"...
2018/03/06
[ "https://wordpress.stackexchange.com/questions/295992", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/138112/" ]
I know that you can install plugin code as part of a theme, but I would like to do it the other way round. I'm developing a plugin that changes many aspects of WordPress and most will not be visible without my theme providing support for it. In other words it makes very little sense to run the plugin without the theme....
Well instead of copying a theme over which would require file permissions, etc, you can add the themes files to the plugin folder and activate it from there: ```php function updateTheme($theme){ update_option('template', $theme); update_option('stylesheet', $theme); update_option('current_theme', $theme); ...
296,038
<p>Is there a WP-CLI command to disable comment windows for all existing posts (pages/blogposts)?</p> <p>I ask this since when I change a theme for a site I have, all pages in that site getting their comment windows again and I need to individually disable comments per each page.</p> <p>In this particular site I have...
[ { "answer_id": 296042, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 4, "selected": true, "text": "<p>Here is an untested suggestion for wp-cli approach:</p>\n\n<p>We can list post IDs of published posts with <em...
2018/03/07
[ "https://wordpress.stackexchange.com/questions/296038", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/136194/" ]
Is there a WP-CLI command to disable comment windows for all existing posts (pages/blogposts)? I ask this since when I change a theme for a site I have, all pages in that site getting their comment windows again and I need to individually disable comments per each page. In this particular site I have up to 10 webpage...
Here is an untested suggestion for wp-cli approach: We can list post IDs of published posts with *open* comment status with: ``` wp post list --post-status=publish --post_type=post comment_status=open --format=ids ``` and update a post to a *closed* comment status with: ``` wp post update 123 --comment_status=clos...
296,056
<p>I have a Multisite setup, and I would like to hide all notices/notifications from the admin pages for everyone but me (the Super Admin). How would I manage to do this?</p> <p>Thank you!</p>
[ { "answer_id": 296060, "author": "Misha Rudrastyh", "author_id": 85985, "author_profile": "https://wordpress.stackexchange.com/users/85985", "pm_score": 4, "selected": true, "text": "<p>Try this code in your custom plugin which is better to activate for the network.</p>\n\n<pre><code>if ...
2018/03/07
[ "https://wordpress.stackexchange.com/questions/296056", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/138051/" ]
I have a Multisite setup, and I would like to hide all notices/notifications from the admin pages for everyone but me (the Super Admin). How would I manage to do this? Thank you!
Try this code in your custom plugin which is better to activate for the network. ``` if ( !is_super_admin() ) { remove_all_actions('admin_notices'); } ```
296,095
<p>i have two WordPress sites with SSO Configurations as described <a href="https://wordpress.stackexchange.com/questions/272122/single-sign-on-between-two-wordpress-website">here</a> but the plugin in the answer didn't work for me so i tried to write a code to add capabilities for second site users:</p> <pre> $wp_user...
[ { "answer_id": 296108, "author": "Felipe Elia", "author_id": 122788, "author_profile": "https://wordpress.stackexchange.com/users/122788", "pm_score": 3, "selected": true, "text": "<p>Try passing the value without serializing it manually, because WordPress will do it for you anyway:</p>\...
2018/03/07
[ "https://wordpress.stackexchange.com/questions/296095", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/123728/" ]
i have two WordPress sites with SSO Configurations as described [here](https://wordpress.stackexchange.com/questions/272122/single-sign-on-between-two-wordpress-website) but the plugin in the answer didn't work for me so i tried to write a code to add capabilities for second site users: ``` $wp_user_query = new WP_Us...
Try passing the value without serializing it manually, because WordPress will do it for you anyway: ``` add_user_meta( $user->id, 'orewpst_capabilities', array( 'author' => 1 ), true ); ``` or ``` update_user_meta( $user->id, 'orewpst_capabilities', array( 'author' => 1 ) ); // it will create the meta data for you ...
296,115
<p>Lets say we have a do_action like this: </p> <pre><code>do_action('some_action'); </code></pre> <p>Doesn't this mean that there has to be a <code>some_action()</code> function somewhere in the wordpress like this for example:</p> <pre><code>function some_action(){ /* blah blah blah*/ } </code></pre> <p>My qu...
[ { "answer_id": 296118, "author": "Alex Sancho", "author_id": 2536, "author_profile": "https://wordpress.stackexchange.com/users/2536", "pm_score": 4, "selected": true, "text": "<p>The param used in <code>do_action</code> isn't a function is just a tag that represents the action called, t...
2018/03/07
[ "https://wordpress.stackexchange.com/questions/296115", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/125637/" ]
Lets say we have a do\_action like this: ``` do_action('some_action'); ``` Doesn't this mean that there has to be a `some_action()` function somewhere in the wordpress like this for example: ``` function some_action(){ /* blah blah blah*/ } ``` My question comes from a `do_action()` at the storefront theme of...
The param used in `do_action` isn't a function is just a tag that represents the action called, the proper way to use an action is attaching functions with `add_action`. You can learn more from <https://developer.wordpress.org/reference/functions/do_action/>
296,129
<p>I'm attempting to create a custom post type (doctors) that will load a custom page template (single-doctors.php). I've set up the custom post type through functions.php, and created a 'new doctor', selected the single-doctors template. But when I go to actually see the page, the template doesnt load and I'm prese...
[ { "answer_id": 296130, "author": "Aleksandar Mitic", "author_id": 91458, "author_profile": "https://wordpress.stackexchange.com/users/91458", "pm_score": 0, "selected": false, "text": "<p>Try this. Comment out this lines: </p>\n\n<pre><code> 'has_archive' =&gt; false,\n 'hie...
2018/03/07
[ "https://wordpress.stackexchange.com/questions/296129", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/138194/" ]
I'm attempting to create a custom post type (doctors) that will load a custom page template (single-doctors.php). I've set up the custom post type through functions.php, and created a 'new doctor', selected the single-doctors template. But when I go to actually see the page, the template doesnt load and I'm presented...
Ok all, I think I figured out the problem...well, problemS. First, credit to @WebElaine, for putting me on the right track with the `unregister_post_type()` function. I unregistered ALL of my post types, then went through and made sure everything was singular with no trailing S. After unregistering everything (and co...
296,154
<p>I managed to make this shortcode work and it shows everything as I want. The only issue I am facing right now is that if I use <code>posts_per_page =&gt; 1</code>, it keeps showing all the posts. What can I do to be able to show only the latest post of the category? I tried: <code>posts_per_page =&gt; 1</code> witho...
[ { "answer_id": 296163, "author": "DHL17", "author_id": 125227, "author_profile": "https://wordpress.stackexchange.com/users/125227", "pm_score": 1, "selected": false, "text": "<p>For Example try this:</p>\n\n<pre><code>function my_shortcode($atts,$content=null)\n{\n extract(shortcode_...
2018/03/08
[ "https://wordpress.stackexchange.com/questions/296154", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/138205/" ]
I managed to make this shortcode work and it shows everything as I want. The only issue I am facing right now is that if I use `posts_per_page => 1`, it keeps showing all the posts. What can I do to be able to show only the latest post of the category? I tried: `posts_per_page => 1` without '', but nothing it's still n...
You have the `posts_per_page` attribute in your shortcode, but you're not actually calling it in your `WP_Query`. Your're doing a few unnecessary things in your code, but for now, the issue at hand is that you need to add: ``` if( !empty( $posts_per_page )) { $query .= '&posts_per_page='.$posts_per_page; } ``` B...
296,170
<p><strong>EDIT:</strong> <em>Based on @TimHallman's answer I have a follow-up question, please see the bottom of this post.</em></p> <p>I am trying to do something that is way over my head and the more I think of it, the more questions I end up with.</p> <p>This is the scenario I have:</p> <ul> <li>Custom posts of ...
[ { "answer_id": 296175, "author": "Tim Hallman", "author_id": 38375, "author_profile": "https://wordpress.stackexchange.com/users/38375", "pm_score": 1, "selected": true, "text": "<p>I suppose a quick and dirty way to achieve what you want is to clear the entire site cache, something like...
2018/03/08
[ "https://wordpress.stackexchange.com/questions/296170", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/90832/" ]
**EDIT:** *Based on @TimHallman's answer I have a follow-up question, please see the bottom of this post.* I am trying to do something that is way over my head and the more I think of it, the more questions I end up with. This is the scenario I have: * Custom posts of type **golfcourse**, each presenting a golf cour...
I suppose a quick and dirty way to achieve what you want is to clear the entire site cache, something like this: ``` function clear_rocket_cache_on_post_save() { rocket_clean_domain(); } add_action( 'save_post', 'clear_rocket_cache_on_post_save' ); ``` Otherwise you'll need to do a query to get the matching pos...
296,184
<p>My plugin needs to store a value (timestamp) in the database. The value isn't associated with any post/page/etc. Its associated with the plugin. Where should I write this value to the database - what table?</p> <p>I've used <code>add_post_meta();</code> before and this works well to store information associated wit...
[ { "answer_id": 296175, "author": "Tim Hallman", "author_id": 38375, "author_profile": "https://wordpress.stackexchange.com/users/38375", "pm_score": 1, "selected": true, "text": "<p>I suppose a quick and dirty way to achieve what you want is to clear the entire site cache, something like...
2018/03/08
[ "https://wordpress.stackexchange.com/questions/296184", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/75260/" ]
My plugin needs to store a value (timestamp) in the database. The value isn't associated with any post/page/etc. Its associated with the plugin. Where should I write this value to the database - what table? I've used `add_post_meta();` before and this works well to store information associated with a post/page. Is the...
I suppose a quick and dirty way to achieve what you want is to clear the entire site cache, something like this: ``` function clear_rocket_cache_on_post_save() { rocket_clean_domain(); } add_action( 'save_post', 'clear_rocket_cache_on_post_save' ); ``` Otherwise you'll need to do a query to get the matching pos...
296,194
<p>My WordPress debug.log is filling up with this group of seven PHP warnings/notices, recurring at least every half an hour...</p> <pre><code>[08-Mar-2018 09:05:03 UTC] PHP Notice: Trying to get property of non-object in /home/mysite/public_html/wp-includes/class-wp-query.php on line 3736 [08-Mar-2018 09:05:03 UTC] ...
[ { "answer_id": 332654, "author": "Ted Stresen-Reuter", "author_id": 112766, "author_profile": "https://wordpress.stackexchange.com/users/112766", "pm_score": 3, "selected": false, "text": "<p>You can get the backtrace by trapping the E_NOTICE message. If you add the following snippet to ...
2018/03/08
[ "https://wordpress.stackexchange.com/questions/296194", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/39300/" ]
My WordPress debug.log is filling up with this group of seven PHP warnings/notices, recurring at least every half an hour... ``` [08-Mar-2018 09:05:03 UTC] PHP Notice: Trying to get property of non-object in /home/mysite/public_html/wp-includes/class-wp-query.php on line 3736 [08-Mar-2018 09:05:03 UTC] PHP Notice: T...
You can get the backtrace by trapping the E\_NOTICE message. If you add the following snippet to wp-config.php just before ``` /* That's all, stop editing! Happy blogging. */ ``` you should see the full backtrace in the error log. ``` set_error_handler(function() { error_log(print_r(debug_backtrace(), true)); ...
296,248
<p>I wrote this simple code to prove what I'm saying:</p> <pre><code>wp_nav_menu( [ 'menu' =&gt; 'Primary Navigation', 'menu_class' =&gt; 'this-is-the-menu-class', 'menu_id' =&gt; 'this-is-the-menu-id', 'container' =&gt; 'div', 'container_class' =&gt; 'this-is-the-container-class', 'container_i...
[ { "answer_id": 296253, "author": "sMyles", "author_id": 51201, "author_profile": "https://wordpress.stackexchange.com/users/51201", "pm_score": 4, "selected": true, "text": "<p>I believe this is caused probably by your theme or another plugin, filtering on <code>wp_nav_menu_args</code> a...
2018/03/08
[ "https://wordpress.stackexchange.com/questions/296248", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/57145/" ]
I wrote this simple code to prove what I'm saying: ``` wp_nav_menu( [ 'menu' => 'Primary Navigation', 'menu_class' => 'this-is-the-menu-class', 'menu_id' => 'this-is-the-menu-id', 'container' => 'div', 'container_class' => 'this-is-the-container-class', 'container_id' => 'this-is-the-container-...
I believe this is caused probably by your theme or another plugin, filtering on `wp_nav_menu_args` and changing the `items_wrap` value. I tested your provided code and the output was correct, using blank WordPress 4.9.4 installation. You could try passing `items_wrap` with default value: ``` wp_nav_menu( [ 'menu'...
296,303
<p>How do I prevent the creation of these when creating a new Multisite?</p> <p>Everytime I create a new multisite this gets created:</p> <ul> <li>Hello World</li> <li>Sample Page</li> <li>A sample Comment</li> </ul> <p>I tried adding this to the <code>functions.php</code></p> <pre><code>add_action( 'wpmu_new_blog'...
[ { "answer_id": 296306, "author": "cjbj", "author_id": 75495, "author_profile": "https://wordpress.stackexchange.com/users/75495", "pm_score": 1, "selected": false, "text": "<p>When you <a href=\"https://developer.wordpress.org/reference/functions/wpmu_create_blog/\" rel=\"nofollow norefe...
2018/03/09
[ "https://wordpress.stackexchange.com/questions/296303", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/138051/" ]
How do I prevent the creation of these when creating a new Multisite? Everytime I create a new multisite this gets created: * Hello World * Sample Page * A sample Comment I tried adding this to the `functions.php` ``` add_action( 'wpmu_new_blog', 'delete_wordpress_defaults', 100, 1 ); function delete_wordpress_def...
When you [create a new site with multisite](https://developer.wordpress.org/reference/functions/wpmu_create_blog/) WP does not automatically change the context. So your action is added to the current site, not the new site. You have to switch first. Like this: ``` add_action ('wpmu_new_blog', 'wpse296303_delete_wordpr...
296,308
<p>I want to replace the following message when creating a user in the dashboard as an administrator: </p> <pre><code>Username: xxx To set your password, visit the following address: https://development.xxx.com/wp-login.php?action=rp&amp;key=FlFdsDeAveg2EN1HuqGB0G&amp;login=xxx%40gmail.com https://development.xxx.c...
[ { "answer_id": 296306, "author": "cjbj", "author_id": 75495, "author_profile": "https://wordpress.stackexchange.com/users/75495", "pm_score": 1, "selected": false, "text": "<p>When you <a href=\"https://developer.wordpress.org/reference/functions/wpmu_create_blog/\" rel=\"nofollow norefe...
2018/03/09
[ "https://wordpress.stackexchange.com/questions/296308", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/-1/" ]
I want to replace the following message when creating a user in the dashboard as an administrator: ``` Username: xxx To set your password, visit the following address: https://development.xxx.com/wp-login.php?action=rp&key=FlFdsDeAveg2EN1HuqGB0G&login=xxx%40gmail.com https://development.xxx.com/wp-login.php ``` ...
When you [create a new site with multisite](https://developer.wordpress.org/reference/functions/wpmu_create_blog/) WP does not automatically change the context. So your action is added to the current site, not the new site. You have to switch first. Like this: ``` add_action ('wpmu_new_blog', 'wpse296303_delete_wordpr...
296,320
<p>I am trying to list posts in a widget I am working on at the moment. However, when I use the get_template_part function in my loop, my site just keeps loading until I get a 500 http error.</p> <pre><code> $args = array( 'numberposts' =&gt; 10, 'orderby' =&gt; 'date', '...
[ { "answer_id": 296306, "author": "cjbj", "author_id": 75495, "author_profile": "https://wordpress.stackexchange.com/users/75495", "pm_score": 1, "selected": false, "text": "<p>When you <a href=\"https://developer.wordpress.org/reference/functions/wpmu_create_blog/\" rel=\"nofollow norefe...
2018/03/09
[ "https://wordpress.stackexchange.com/questions/296320", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/118091/" ]
I am trying to list posts in a widget I am working on at the moment. However, when I use the get\_template\_part function in my loop, my site just keeps loading until I get a 500 http error. ``` $args = array( 'numberposts' => 10, 'orderby' => 'date', 'order' ...
When you [create a new site with multisite](https://developer.wordpress.org/reference/functions/wpmu_create_blog/) WP does not automatically change the context. So your action is added to the current site, not the new site. You have to switch first. Like this: ``` add_action ('wpmu_new_blog', 'wpse296303_delete_wordpr...
296,341
<p>Is it possible to use WordPress to serve up a hard coded page that already exists? The goal is that we want to make some simple shorter urls but not have a huge mess in the root directory of our website.</p>
[ { "answer_id": 296306, "author": "cjbj", "author_id": 75495, "author_profile": "https://wordpress.stackexchange.com/users/75495", "pm_score": 1, "selected": false, "text": "<p>When you <a href=\"https://developer.wordpress.org/reference/functions/wpmu_create_blog/\" rel=\"nofollow norefe...
2018/03/09
[ "https://wordpress.stackexchange.com/questions/296341", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/138324/" ]
Is it possible to use WordPress to serve up a hard coded page that already exists? The goal is that we want to make some simple shorter urls but not have a huge mess in the root directory of our website.
When you [create a new site with multisite](https://developer.wordpress.org/reference/functions/wpmu_create_blog/) WP does not automatically change the context. So your action is added to the current site, not the new site. You have to switch first. Like this: ``` add_action ('wpmu_new_blog', 'wpse296303_delete_wordpr...
296,366
<p>I have created a small shortcode function with attributes to review if attributes are handled properly. That's the case and now I would like to use the attribute in a SELECT statement. But the database does not provide any values. The SQL statement without variable in the WHERE condition is okay. </p> <p>To test ...
[ { "answer_id": 296370, "author": "J.BizMai", "author_id": 128094, "author_profile": "https://wordpress.stackexchange.com/users/128094", "pm_score": -1, "selected": false, "text": "<p>First of all, you seem to get a mysql error. <code>$attr[text]</code> is a string so you need to wrap it ...
2018/03/09
[ "https://wordpress.stackexchange.com/questions/296366", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/138252/" ]
I have created a small shortcode function with attributes to review if attributes are handled properly. That's the case and now I would like to use the attribute in a SELECT statement. But the database does not provide any values. The SQL statement without variable in the WHERE condition is okay. To test shortcodes...
Here's the SQL query: ``` $simplelist = $wpdb->get_results("SELECT `Row1`, `Row2` FROM `table` WHERE `Row1` = " . $atts[text] . " ORDER BY `Row1` ASC"); ``` Lets pretend we're the computer and run i...
296,416
<p>I have two hooks in separate HTML request.</p> <p>I have to pass some data i.e. variable from one to the other.</p> <p>What is the most practical and transparent method for it?</p>
[ { "answer_id": 296418, "author": "Johansson", "author_id": 94498, "author_profile": "https://wordpress.stackexchange.com/users/94498", "pm_score": 2, "selected": false, "text": "<p>It's not possible to pass data from one HTTP request to another one on the fly. Once the script is finished...
2018/03/11
[ "https://wordpress.stackexchange.com/questions/296416", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/137445/" ]
I have two hooks in separate HTML request. I have to pass some data i.e. variable from one to the other. What is the most practical and transparent method for it?
It's not possible to pass data from one HTTP request to another one on the fly. Once the script is finished, the data will be discarded. What you can do is to store the data in a transient, and then retrieve it later. Here's a simple example using [`set_transient()`](https://codex.wordpress.org/Function_Reference/set_...