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
250,547
<p>I have created a custom sidebar widgets using below code : </p> <pre><code>register_sidebar(array( 'id' =&gt; 'sidebar-widget-1', 'name' =&gt; 'Sidebar Widget 1', 'before_widget' =&gt; '', 'after_widget' =&gt; '', 'before_title' =&gt; '', 'after_title' =&gt; '', ...
[ { "answer_id": 250534, "author": "jetyet47", "author_id": 91783, "author_profile": "https://wordpress.stackexchange.com/users/91783", "pm_score": 2, "selected": false, "text": "<p>Not totally clear what you're asking, but post_class is probably your best bet.</p>\n\n<pre><code>&lt;?php p...
2016/12/28
[ "https://wordpress.stackexchange.com/questions/250547", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/74147/" ]
I have created a custom sidebar widgets using below code : ``` register_sidebar(array( 'id' => 'sidebar-widget-1', 'name' => 'Sidebar Widget 1', 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', )); ``` and it is showing in `...
Not totally clear what you're asking, but post\_class is probably your best bet. ``` <?php post_class(); ?> ``` More info: <https://codex.wordpress.org/Function_Reference/post_class>
250,565
<p>Based on <a href="https://wordpress.stackexchange.com/questions/50233/how-to-develop-a-theme-while-having-another-show-up?noredirect=1&amp;lq=1">answers like this one</a>, I made a small plugin to display a theme displaying a "Coming soon" theme, whilst our team of editors can fill in the final theme.</p> <p>It wor...
[ { "answer_id": 250573, "author": "cjbj", "author_id": 75495, "author_profile": "https://wordpress.stackexchange.com/users/75495", "pm_score": 2, "selected": false, "text": "<p><a href=\"https://codex.wordpress.org/Plugin_API/Filter_Reference\" rel=\"nofollow noreferrer\">Filters</a>, unl...
2016/12/28
[ "https://wordpress.stackexchange.com/questions/250565", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/82/" ]
Based on [answers like this one](https://wordpress.stackexchange.com/questions/50233/how-to-develop-a-theme-while-having-another-show-up?noredirect=1&lq=1), I made a small plugin to display a theme displaying a "Coming soon" theme, whilst our team of editors can fill in the final theme. It worked yesterday, but today,...
[Filters](https://codex.wordpress.org/Plugin_API/Filter_Reference), unlike actions, don't run at a specific moment, but when the function they are attached too, is called. The template-filter is called from [`get_template`](https://developer.wordpress.org/reference/functions/get_template/) and the stylesheet-filter fro...
250,587
<p>My understanding of private posts/pages is that they only work when you are logged into the WP admin system as an administrator or editor. </p> <p>I have a site where I need to occasionally share custom posts to users via links and I don't want them to appear elsewhere on the site. Setting posts to "private" al...
[ { "answer_id": 250613, "author": "jetyet47", "author_id": 91783, "author_profile": "https://wordpress.stackexchange.com/users/91783", "pm_score": 0, "selected": false, "text": "<p>Probably plugin territory, because as you mention the way private pages work, they are only visible to logge...
2016/12/28
[ "https://wordpress.stackexchange.com/questions/250587", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/28543/" ]
My understanding of private posts/pages is that they only work when you are logged into the WP admin system as an administrator or editor. I have a site where I need to occasionally share custom posts to users via links and I don't want them to appear elsewhere on the site. Setting posts to "private" almost does what...
If you *don't* want to use a plugin (or can't find one that does what you're needing), you might want to approach it this way: 1. Add a [custom meta box](https://developer.wordpress.org/reference/functions/add_meta_box/) that allows you to mark the post as `hidden`. 2. Modifying the query with [pre\_get\_posts](https:...
250,614
<p>I am trying to create taxonomy elements (the taxonomies are already registered) from the front end using the REST Api v2. I am able to do so except not able to save the meta fields from the taxonomies.</p> <hr> <p>I have a registered taxonomy ("place") and I am trying to create elements for it using the Rest Api.<...
[ { "answer_id": 250695, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 0, "selected": false, "text": "<p>You should pass your meta value as an array to your meta key.</p>\n\n<pre><code>var place_new = new wp.api.mode...
2016/12/28
[ "https://wordpress.stackexchange.com/questions/250614", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/16533/" ]
I am trying to create taxonomy elements (the taxonomies are already registered) from the front end using the REST Api v2. I am able to do so except not able to save the meta fields from the taxonomies. --- I have a registered taxonomy ("place") and I am trying to create elements for it using the Rest Api. The taxono...
I think you need an `update_callback` in `register_rest_field()`. Please note that I haven't tested this. ``` add_action( 'rest_api_init', 'slug_register_meta' ); function slug_register_meta() { register_rest_field( 'place', 'meta', array( 'get_callback' => 'slug_get_meta', ...
250,616
<p><strong>For example:</strong> </p> <ul> <li><code>mydomain.com/embed</code> automatically redirecting to homepage although I haven't set redirection. </li> <li>I want to add a page in my website name embed and for this page URL<br> automatically becoming <code>mydomain.com/embed-2</code>.</li> </ul> <p>I checked e...
[ { "answer_id": 250695, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 0, "selected": false, "text": "<p>You should pass your meta value as an array to your meta key.</p>\n\n<pre><code>var place_new = new wp.api.mode...
2016/12/28
[ "https://wordpress.stackexchange.com/questions/250616", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109805/" ]
**For example:** * `mydomain.com/embed` automatically redirecting to homepage although I haven't set redirection. * I want to add a page in my website name embed and for this page URL automatically becoming `mydomain.com/embed-2`. I checked everything, there is no existing or trash post, page, tags Etc. **How t...
I think you need an `update_callback` in `register_rest_field()`. Please note that I haven't tested this. ``` add_action( 'rest_api_init', 'slug_register_meta' ); function slug_register_meta() { register_rest_field( 'place', 'meta', array( 'get_callback' => 'slug_get_meta', ...
250,626
<p>Is it possible to add controls to sub panels of the widgets panel in the customizer? If yes, how do I address them? The widget area would be named “top-widget-area”</p> <p>Neither addressing:</p> <pre><code>'panel' =&gt; 'widgets-top-widget-area' </code></pre> <p>nor</p> <pre><code>'section' =&gt; 'widgets-top-w...
[ { "answer_id": 250695, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 0, "selected": false, "text": "<p>You should pass your meta value as an array to your meta key.</p>\n\n<pre><code>var place_new = new wp.api.mode...
2016/12/28
[ "https://wordpress.stackexchange.com/questions/250626", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109814/" ]
Is it possible to add controls to sub panels of the widgets panel in the customizer? If yes, how do I address them? The widget area would be named “top-widget-area” Neither addressing: ``` 'panel' => 'widgets-top-widget-area' ``` nor ``` 'section' => 'widgets-top-widget-area' ``` in `$wp_customize->add_control` ...
I think you need an `update_callback` in `register_rest_field()`. Please note that I haven't tested this. ``` add_action( 'rest_api_init', 'slug_register_meta' ); function slug_register_meta() { register_rest_field( 'place', 'meta', array( 'get_callback' => 'slug_get_meta', ...
250,633
<p>I am making a wordpress site but i need little help,</p> <p>What I have is a function with Next and Previous buttons to list projects, but when i go to the last project the Next button is gone.</p> <p>What I want to do is, when I go to the last project I hit "Next" and direct me to the first project something like...
[ { "answer_id": 250644, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 2, "selected": true, "text": "<p>Use <a href=\"https://codex.wordpress.org/Function_Reference/get_adjacent_post\" rel=\"nofollow noreferre...
2016/12/29
[ "https://wordpress.stackexchange.com/questions/250633", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/101369/" ]
I am making a wordpress site but i need little help, What I have is a function with Next and Previous buttons to list projects, but when i go to the last project the Next button is gone. What I want to do is, when I go to the last project I hit "Next" and direct me to the first project something like loop slide Here...
Use [get\_adjacent\_post](https://codex.wordpress.org/Function_Reference/get_adjacent_post) to first see if there's actually a next post: ``` if (get_adjacent_post (false, '', false)) { next_post_link ('%link', 'Next Project &gt;', true, '', 'projectcategory'); } else { // manually create link to first post he...
250,637
<p>Ultimately, I'm really confused on how exactly you create a single class that affects each post in a static home page "recent post" type content area. I want to essentially have it where there's a post with a background, a space, then the next post with the same background, but not have the background behind all the...
[ { "answer_id": 250639, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 2, "selected": true, "text": "<p>Wordpress already generates class for each posts, you can use these classes using the <a href=\"https://develope...
2016/12/29
[ "https://wordpress.stackexchange.com/questions/250637", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/108586/" ]
Ultimately, I'm really confused on how exactly you create a single class that affects each post in a static home page "recent post" type content area. I want to essentially have it where there's a post with a background, a space, then the next post with the same background, but not have the background behind all the po...
Wordpress already generates class for each posts, you can use these classes using the [**`post_class`**](https://developer.wordpress.org/reference/functions/post_class/) function. **Note:** The function can be used either within the loop or by passing the `$post_id` So you would have ``` <ul> <?php $the_query = ...
250,662
<p>Let's say I have two pages on a WordPress site with content (text, HTML, shortcodes). How could I create a shortcode to display the content from Page A when Page B loads?</p> <p>I recognize of course that this has the potential to become an infinite loop if used improperly and that there are potential formatting ha...
[ { "answer_id": 250688, "author": "robin416", "author_id": 109865, "author_profile": "https://wordpress.stackexchange.com/users/109865", "pm_score": 0, "selected": false, "text": "<p><P>Jeff Starr's <A HREF=\"https://wordpress.org/plugins/simple-custom-content/\" rel=\"nofollow noreferrer...
2016/12/29
[ "https://wordpress.stackexchange.com/questions/250662", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/96983/" ]
Let's say I have two pages on a WordPress site with content (text, HTML, shortcodes). How could I create a shortcode to display the content from Page A when Page B loads? I recognize of course that this has the potential to become an infinite loop if used improperly and that there are potential formatting hazards. Bes...
You can create a shortcode as below: ``` function wpse250662_post_content_shortcode($atts) { $args = shortcode_atts( array( 'pagename' => '' ), $atts ); $query = new WP_Query( $args ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); $con...
250,675
<p>I was importing my website' database on to another server but it is showing this error which I have no idea about:</p> <p><img src="https://i.imgur.com/6vRhZag.png" alt=""></p> <p>I tried importing the database multiple times but failed. I also checked 'Add Drop Table' field that comes when exporting the database ...
[ { "answer_id": 250676, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 4, "selected": true, "text": "<p>This issue is as a result of your server not supporting the <code>utf8mb4_unicode_520_ci</code> collation type.<...
2016/12/29
[ "https://wordpress.stackexchange.com/questions/250675", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/106457/" ]
I was importing my website' database on to another server but it is showing this error which I have no idea about: ![](https://i.imgur.com/6vRhZag.png) I tried importing the database multiple times but failed. I also checked 'Add Drop Table' field that comes when exporting the database file but it didn't do anything.
This issue is as a result of your server not supporting the `utf8mb4_unicode_520_ci` collation type. To resolve this you should convert the collation for all tables with `utf8mb4_unicode_520_ci` to `utf8_general_ci` **If you're exporting through phpmyadmin, you can:** 1. Click the "Export" tab for the database 2. Cl...
250,725
<p>Now its display only 12 item</p> <p>Here is code. can you please anyone help me</p> <pre><code>&lt;?php query_posts('post_type=faq&amp;post_status=publish&amp;order=DESC&amp;orderby=date=' ) ?&gt; &lt;?php if( have_posts() ): ?&gt; &lt;ul id="myUL" class="margb-40"&gt; &lt...
[ { "answer_id": 250726, "author": "rudtek", "author_id": 77767, "author_profile": "https://wordpress.stackexchange.com/users/77767", "pm_score": 0, "selected": false, "text": "<p>you could always add: </p>\n\n<pre><code>'posts_per_page'=-1\n\n&lt;?php query_posts('posts_per_page=-1&amp;po...
2016/12/29
[ "https://wordpress.stackexchange.com/questions/250725", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109890/" ]
Now its display only 12 item Here is code. can you please anyone help me ``` <?php query_posts('post_type=faq&post_status=publish&order=DESC&orderby=date=' ) ?> <?php if( have_posts() ): ?> <ul id="myUL" class="margb-40"> <?php while( have_posts() ): the_post(); ?> ```
You can use [**WP\_Query**](https://codex.wordpress.org/Class_Reference/WP_Query) ``` <?php $args = array( 'post_type' => 'faq', 'post_status' => 'publish', 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => -1 ); $query = new WP_Qu...
250,734
<p>I have the following code and i am trying to exclude a specific category id ex-144</p> <pre><code>function product_count_shortcode( ) { $count_posts = wp_count_posts( 'product' ); return $count_posts-&gt;publish; } add_shortcode( 'product_count', 'product_count_shortcode' ); </code></pre> <p>How can exclud...
[ { "answer_id": 250726, "author": "rudtek", "author_id": 77767, "author_profile": "https://wordpress.stackexchange.com/users/77767", "pm_score": 0, "selected": false, "text": "<p>you could always add: </p>\n\n<pre><code>'posts_per_page'=-1\n\n&lt;?php query_posts('posts_per_page=-1&amp;po...
2016/12/29
[ "https://wordpress.stackexchange.com/questions/250734", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/108699/" ]
I have the following code and i am trying to exclude a specific category id ex-144 ``` function product_count_shortcode( ) { $count_posts = wp_count_posts( 'product' ); return $count_posts->publish; } add_shortcode( 'product_count', 'product_count_shortcode' ); ``` How can exclude one category?
You can use [**WP\_Query**](https://codex.wordpress.org/Class_Reference/WP_Query) ``` <?php $args = array( 'post_type' => 'faq', 'post_status' => 'publish', 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => -1 ); $query = new WP_Qu...
250,753
<p>I need to get a list of all pages in a dropdown list, so I can get the page id of the selected page to store in the options of my plugin.</p> <p>Right now I have:</p> <pre><code>?&gt; &lt;input name='wpplf23_plugin_options[thankyou_page]' type='number' value='&lt;?php if ( ( isset( $options['thankyou_page'] ) ...
[ { "answer_id": 250755, "author": "AddWeb Solution Pvt Ltd", "author_id": 73643, "author_profile": "https://wordpress.stackexchange.com/users/73643", "pm_score": 1, "selected": false, "text": "<p>Try below code.</p>\n\n<pre><code>&lt;select name=\"page\"&gt; \n &lt;option value=\"\"&gt...
2016/12/30
[ "https://wordpress.stackexchange.com/questions/250753", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109162/" ]
I need to get a list of all pages in a dropdown list, so I can get the page id of the selected page to store in the options of my plugin. Right now I have: ``` ?> <input name='wpplf23_plugin_options[thankyou_page]' type='number' value='<?php if ( ( isset( $options['thankyou_page'] ) ) ) { echo $options['thankyou_...
Iam using following code to display a page select dropdown menu on an plugin option page. If you select an page and save it, the next time you visit the option-site, you will also see which page was saved. (so no more "select page") You can use the WordPress *selected()* function, you can find more details here: [htt...
250,761
<p>Example: I have following HTML code and where should I place that <code>bootstrap.min.css</code> link. If I place that link in HTML code itself, when the page is published it's not loading the CSS.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;title&gt;Bootstrap Example&lt;/title&gt...
[ { "answer_id": 250764, "author": "dgarceran", "author_id": 109222, "author_profile": "https://wordpress.stackexchange.com/users/109222", "pm_score": 1, "selected": false, "text": "<p>Use <a href=\"https://developer.wordpress.org/reference/functions/wp_enqueue_style/\" rel=\"nofollow nore...
2016/12/30
[ "https://wordpress.stackexchange.com/questions/250761", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109905/" ]
Example: I have following HTML code and where should I place that `bootstrap.min.css` link. If I place that link in HTML code itself, when the page is published it's not loading the CSS. ``` <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" cont...
Use [wp\_enqueue\_style()](https://developer.wordpress.org/reference/functions/wp_enqueue_style/) in your functions.php: ``` function custom_wp_enqueue_style() { wp_enqueue_style( 'bootstrapcdn', "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" ); } add_action ( 'wp_enqueue_scripts', 'cu...
250,797
<p>I have made a query which gives me 8 results. I need to show these in 2 columns of 4 items.</p> <p>This is my query :</p> <pre><code> $args = array( 'post_type' =&gt; 'event', 'meta_key' =&gt; 'date', 'orderby' =&gt; 'meta_value_num', ...
[ { "answer_id": 250808, "author": "Anas Bouayour", "author_id": 109935, "author_profile": "https://wordpress.stackexchange.com/users/109935", "pm_score": 0, "selected": false, "text": "<p>if i realy understand your question, put the array in a loop and use a variable as counter </p>\n\n<p...
2016/12/30
[ "https://wordpress.stackexchange.com/questions/250797", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/101046/" ]
I have made a query which gives me 8 results. I need to show these in 2 columns of 4 items. This is my query : ``` $args = array( 'post_type' => 'event', 'meta_key' => 'date', 'orderby' => 'meta_value_num', 'order' => 'ASC', ...
There's no need to split the array, you can just close the first div once you've counted up to four elements of the array. ``` $args = array( 'post_type' => 'event', 'meta_key' => 'date', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'posts_per_page' => 8, 'meta_query' => array( 'key...
250,810
<p>I downloaded a whole WP install and moved it to a LAMP test environment in order to update it. The original site could be found under example.com, the test site should be under example.com.mytestdomain.com aka {testurl}. In order to achieve that, I created a local DNS record and I changed the site url as well as the...
[ { "answer_id": 250814, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 0, "selected": false, "text": "<p>You should define both the <code>WP_SITEURL</code> and <code>WP_HOME</code> in your test wp-config.php file, do...
2016/12/30
[ "https://wordpress.stackexchange.com/questions/250810", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109938/" ]
I downloaded a whole WP install and moved it to a LAMP test environment in order to update it. The original site could be found under example.com, the test site should be under example.com.mytestdomain.com aka {testurl}. In order to achieve that, I created a local DNS record and I changed the site url as well as the ho...
You may have some problem with JavaScript on your website, with the hardcoded URLs. As I can see you are trying to create the test environment. This is good, and I like people creating the test environments. You need to go to through your code, JavaScript and PHP to seek for the hardcoded URLs. Also it is good to hav...
250,837
<p>I am trying to get <code>add_rewrite_rule</code> working to extract a param from url and pass it through to the request. Seen a number of posts about this, but can't seem to get it working.</p> <p>If a url begins with a certain string, I would like to remove it from the url and pass it as a query params.</p> <p>Ex...
[ { "answer_id": 250972, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 4, "selected": false, "text": "<p>A basic rule that would work for your example:</p>\n\n<pre><code>function wpd_foo_rewrite_rule() {\n add_rewrit...
2016/12/30
[ "https://wordpress.stackexchange.com/questions/250837", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/8642/" ]
I am trying to get `add_rewrite_rule` working to extract a param from url and pass it through to the request. Seen a number of posts about this, but can't seem to get it working. If a url begins with a certain string, I would like to remove it from the url and pass it as a query params. Example request url: ``` http...
Ok, I've gotten working examples for all 3 types of requests. It took a ton of experimenting and messing around in order to get them working. I guess Milo is good at nudging people into answering their own questions. After countless changes and refreshing the permalinks I realized it was much easier to figure out the...
250,861
<p>i create a custom page to display loop of cpt with custom field. </p> <p>I need to add a numberic pagination and i try with this code but not work.</p> <p><strong>Functions.php</strong></p> <pre><code>function pagination_bar() { global $wp_query; $total_pages = $wp_query-&gt;max_num_pages; if ($tota...
[ { "answer_id": 250866, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 4, "selected": true, "text": "<p>You're referencing the <strong><code>global $wp_query</code></strong> object in your function which you've reset...
2016/12/31
[ "https://wordpress.stackexchange.com/questions/250861", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/51160/" ]
i create a custom page to display loop of cpt with custom field. I need to add a numberic pagination and i try with this code but not work. **Functions.php** ``` function pagination_bar() { global $wp_query; $total_pages = $wp_query->max_num_pages; if ($total_pages > 1){ $current_page = max(1,...
You're referencing the **`global $wp_query`** object in your function which you've reset using **`wp_reset_query()`**. You can resolve the pagination by passing your custom **`$loop`** WP\_Query object to the function. I also changed **`wp_reset_query`** to **`wp_reset_postdata`** Also you're making the call to your...
250,871
<p>Trying to populate a drop down element of a html form in a word press page with data from SQL query in a php file in a php directory: <code>site/php/</code>.</p> <p><strong>Php code is working fine:</strong></p> <hr> <pre><code>&lt;?php require_once "connectPDO.php"; define('WP_USE_THEMES', false); require('../wp...
[ { "answer_id": 250876, "author": "Vitzkrieg", "author_id": 109973, "author_profile": "https://wordpress.stackexchange.com/users/109973", "pm_score": 0, "selected": false, "text": "<p>I would first check that <code>$value</code> is not null. Also, would it make more sense to call <code>un...
2016/12/31
[ "https://wordpress.stackexchange.com/questions/250871", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109971/" ]
Trying to populate a drop down element of a html form in a word press page with data from SQL query in a php file in a php directory: `site/php/`. **Php code is working fine:** --- ``` <?php require_once "connectPDO.php"; define('WP_USE_THEMES', false); require('../wp-load.php'); require_once('../wp-config.php'); re...
Thanks everybody for your answers. You bring me value clues. Finally I opted to make the query directly from wordpress page with the wordpress sintax for the defaults wordpress tables, using a little trick: Including my custom tables in wp-includes/wp-db.php. wordpress code: ``` <?php global $current_user; get_curren...
250,879
<p>I have a small bit of hourly-changing css and I want to</p> <ol> <li><p>keep it in a second file (apart from style.css) and </p></li> <li><p>load it <em>after</em> my theme's <code>style.css</code> file.</p></li> </ol> <p>I believe I can make it load before <code>style.css</code> by setting its priority to the <co...
[ { "answer_id": 250881, "author": "CoderScissorhands", "author_id": 105196, "author_profile": "https://wordpress.stackexchange.com/users/105196", "pm_score": 0, "selected": false, "text": "<h2>The Dependency Solution</h2>\n<p>One functional solution I found and successfully tested came fr...
2016/12/31
[ "https://wordpress.stackexchange.com/questions/250879", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/105196/" ]
I have a small bit of hourly-changing css and I want to 1. keep it in a second file (apart from style.css) and 2. load it *after* my theme's `style.css` file. I believe I can make it load before `style.css` by setting its priority to the `style.css` minus one (e.g. if the main style.css has a priority of 10, my bit o...
When you properly enqueue a file, an instance of the [`wp_styles`](https://developer.wordpress.org/reference/classes/wp_styles/) ([more on this](https://codex.wordpress.org/Class_Reference/WP_Styles)) class is created. The priority of actions is ignored. So it doesn't matter if you write anything like ``` add_action (...
250,883
<p>Does anybody know how to exclude pingbacks from this query? I tried to add <code>AND post_type = 'comment'</code> after <code>AND post_password = ''</code> but this didn't work.</p> <pre><code>$query = "select wp_posts.*, coalesce(( select max(comment_date) ...
[ { "answer_id": 250887, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 0, "selected": false, "text": "<p>The <a href=\"https://codex.wordpress.org/Database_Description#Table:_wp_comments\" rel=\"nofollow noref...
2016/12/31
[ "https://wordpress.stackexchange.com/questions/250883", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/33797/" ]
Does anybody know how to exclude pingbacks from this query? I tried to add `AND post_type = 'comment'` after `AND post_password = ''` but this didn't work. ``` $query = "select wp_posts.*, coalesce(( select max(comment_date) from $wpdb->comments w...
You can achieve this by excluding `pingback` from the `comment_type` column of wordpress [**comments table**](https://codex.wordpress.org/Database_Description#Table:_wp_comments) ``` $query = "select wp_posts.*, coalesce(( select max(comment_date) from ...
250,931
<p>I am still a bit new to wordpress development and I am facing a issue that I cant figure out.</p> <p>My wordpress website theme uses the following code to display 3 categorys that show a image, category name and a link.</p> <pre><code>&lt;?php echo do_shortcode('[product_categories number="' . $number . '" parent=...
[ { "answer_id": 250887, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 0, "selected": false, "text": "<p>The <a href=\"https://codex.wordpress.org/Database_Description#Table:_wp_comments\" rel=\"nofollow noref...
2017/01/01
[ "https://wordpress.stackexchange.com/questions/250931", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110017/" ]
I am still a bit new to wordpress development and I am facing a issue that I cant figure out. My wordpress website theme uses the following code to display 3 categorys that show a image, category name and a link. ``` <?php echo do_shortcode('[product_categories number="' . $number . '" parent="0" columns="3"]'); ?> ...
You can achieve this by excluding `pingback` from the `comment_type` column of wordpress [**comments table**](https://codex.wordpress.org/Database_Description#Table:_wp_comments) ``` $query = "select wp_posts.*, coalesce(( select max(comment_date) from ...
250,940
<p>I have a wordpress page that i'm trying to gain access to. I currently have access to the phpadmin database and I can easily create a new password. But I'm actually looking to see what the actual password is. There is only one user account, which is the admin. But i'm able to create other users accounts if needed. I...
[ { "answer_id": 250887, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 0, "selected": false, "text": "<p>The <a href=\"https://codex.wordpress.org/Database_Description#Table:_wp_comments\" rel=\"nofollow noref...
2017/01/01
[ "https://wordpress.stackexchange.com/questions/250940", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/107806/" ]
I have a wordpress page that i'm trying to gain access to. I currently have access to the phpadmin database and I can easily create a new password. But I'm actually looking to see what the actual password is. There is only one user account, which is the admin. But i'm able to create other users accounts if needed. Is t...
You can achieve this by excluding `pingback` from the `comment_type` column of wordpress [**comments table**](https://codex.wordpress.org/Database_Description#Table:_wp_comments) ``` $query = "select wp_posts.*, coalesce(( select max(comment_date) from ...
250,952
<p>I'd like to display the sale price of a product before the regular (discounted) price. I know this has something to do with <code>get_price_html</code>. By default, this outputs something like:</p> <pre><code>&lt;del&gt;regular price&lt;/del&gt; &lt;ins&gt;sale price&lt;/ins&gt; </code></pre> <p>I want to change t...
[ { "answer_id": 267169, "author": "Tushar Satani", "author_id": 119866, "author_profile": "https://wordpress.stackexchange.com/users/119866", "pm_score": 0, "selected": false, "text": "<p>Price is come from <code>price.php</code> file in woocommerce plugin. inside this file there is funct...
2017/01/01
[ "https://wordpress.stackexchange.com/questions/250952", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/106693/" ]
I'd like to display the sale price of a product before the regular (discounted) price. I know this has something to do with `get_price_html`. By default, this outputs something like: ``` <del>regular price</del> <ins>sale price</ins> ``` I want to change the output so it looks like this (basically, the two prices ar...
You have to change this in functions.php ``` if (!function_exists('my_commonPriceHtml')) { function my_commonPriceHtml($price_amt, $regular_price, $sale_price) { $html_price = '<p class="price">'; //if product is in sale if (($price_amt == $sale_price) && ($sale_price != 0)) { $html_price .= '<ins...
250,959
<p>I've been trying to find a decent solution to a problem for a while now. In the theme I'm building I have a top "admin bar" menu with some contact links and below that my "logo area" and a main menu.</p> <p>I would like to merge these menus into one single menu in mobile view but still keep some form of control ove...
[ { "answer_id": 250965, "author": "prosti", "author_id": 88606, "author_profile": "https://wordpress.stackexchange.com/users/88606", "pm_score": -1, "selected": false, "text": "<p>I think you just need coaching. I would go with creating the 4-th menu automatically based on the other two. ...
2017/01/01
[ "https://wordpress.stackexchange.com/questions/250959", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/94259/" ]
I've been trying to find a decent solution to a problem for a while now. In the theme I'm building I have a top "admin bar" menu with some contact links and below that my "logo area" and a main menu. I would like to merge these menus into one single menu in mobile view but still keep some form of control over each sep...
I had the same problem. The solution I chose was to "merge" the menus by placing them under a single div wrapper but have them on separate div class. Something like this: ``` <div class="menu-wrapper"> <div class="menu1"> <?php wp_nav_menu( array( 'theme_location' => 'menu-1', ...
250,961
<p>I want to customize my individual posts. I have an example of what I'm trying to achieve below. Would I make a custom post template for this? If so how would I do this? Or should I add to my single.php? Thanks in advance.</p> <p>What I want my individual post pages to look like. I want two pictures side by side ...
[ { "answer_id": 250965, "author": "prosti", "author_id": 88606, "author_profile": "https://wordpress.stackexchange.com/users/88606", "pm_score": -1, "selected": false, "text": "<p>I think you just need coaching. I would go with creating the 4-th menu automatically based on the other two. ...
2017/01/01
[ "https://wordpress.stackexchange.com/questions/250961", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/101743/" ]
I want to customize my individual posts. I have an example of what I'm trying to achieve below. Would I make a custom post template for this? If so how would I do this? Or should I add to my single.php? Thanks in advance. What I want my individual post pages to look like. I want two pictures side by side that are the ...
I had the same problem. The solution I chose was to "merge" the menus by placing them under a single div wrapper but have them on separate div class. Something like this: ``` <div class="menu-wrapper"> <div class="menu1"> <?php wp_nav_menu( array( 'theme_location' => 'menu-1', ...
250,962
<p>I creating website and I need to have different homepages for logged in and logged off users. I have page 'Home page' which is set as home page and is filled with information about my site and pictures and simple page 'Home logged in' which was set as BuddyPress activity stream. What I need is: - User A is visiting...
[ { "answer_id": 251016, "author": "Pete", "author_id": 37346, "author_profile": "https://wordpress.stackexchange.com/users/37346", "pm_score": 2, "selected": false, "text": "<p>Can you use this to redirect the logged out users?</p>\n\n<pre><code>&lt;?php if ( !is_user_logged_in() { ?&gt;\...
2017/01/01
[ "https://wordpress.stackexchange.com/questions/250962", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/86168/" ]
I creating website and I need to have different homepages for logged in and logged off users. I have page 'Home page' which is set as home page and is filled with information about my site and pictures and simple page 'Home logged in' which was set as BuddyPress activity stream. What I need is: - User A is visiting we...
Can you use this to redirect the logged out users? ``` <?php if ( !is_user_logged_in() { ?> <?php wp_redirect( 'https://yourdomain.com.au/logoutpage', 302 ); exit; ?> <?php } ?> ``` or this solution? [setting a specific home page for logged in users](https://wordpress.stackexchange.com/questions/225040/setting-a-spe...
250,989
<p>I need to show a new post marker for unread posts, placed after its date as is shown in the image below: </p> <p><a href="https://i.stack.imgur.com/yebGg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yebGg.jpg" alt="enter image description here"></a></p> <p>Any tips?</p>
[ { "answer_id": 250991, "author": "dgarceran", "author_id": 109222, "author_profile": "https://wordpress.stackexchange.com/users/109222", "pm_score": 1, "selected": false, "text": "<p>You can use <a href=\"https://codex.wordpress.org/Function_Reference/update_user_meta\" rel=\"nofollow no...
2017/01/02
[ "https://wordpress.stackexchange.com/questions/250989", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/33903/" ]
I need to show a new post marker for unread posts, placed after its date as is shown in the image below: [![enter image description here](https://i.stack.imgur.com/yebGg.jpg)](https://i.stack.imgur.com/yebGg.jpg) Any tips?
You can use [update\_user\_meta()](https://codex.wordpress.org/Function_Reference/update_user_meta) and [get\_user\_meta()](https://codex.wordpress.org/Function_Reference/get_user_meta), where you can store and retrieve a value related to a key and a user, like `'read_post_' . $post_id` for example. Inside [The Loop](...
250,999
<p>I'm trying to get 2 php functions with my custom field to work together with a custom field. they both work by themselves great but I can't get them to work together.</p> <p>The first function hides the last X characters of a custom field</p> <pre><code>&lt;?php $custom_field = (string) get_post_meta( $post-&gt;ID...
[ { "answer_id": 251004, "author": "prosti", "author_id": 88606, "author_profile": "https://wordpress.stackexchange.com/users/88606", "pm_score": 2, "selected": true, "text": "<p>I had the same problem.</p>\n\n<pre><code>echo substr( $custom_field, 0, -6 );\necho str_replace(' ', '', $cust...
2017/01/02
[ "https://wordpress.stackexchange.com/questions/250999", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/37346/" ]
I'm trying to get 2 php functions with my custom field to work together with a custom field. they both work by themselves great but I can't get them to work together. The first function hides the last X characters of a custom field ``` <?php $custom_field = (string) get_post_meta( $post->ID, "XYZ", true ); echo subst...
I had the same problem. ``` echo substr( $custom_field, 0, -6 ); echo str_replace(' ', '', $custom_field); ``` I think I solved it this way. ``` echo substr( str_replace(' ', '', $custom_field), 0, -6 ); ```
251,007
<p>I need to replace featured images on pages with a video if certain posts contain a video from YouTube, Vimeo, other video hosting services allowed by WordPress. </p> <p>Here's the pseudo code that I want to use on a custom page:</p> <pre><code>if ( has_post_thumbnail( get_the_ID() { if has_video(pseudocode to ...
[ { "answer_id": 251056, "author": "rudtek", "author_id": 77767, "author_profile": "https://wordpress.stackexchange.com/users/77767", "pm_score": 3, "selected": true, "text": "<p>Let's say for simplicity that you're using <a href=\"https://www.advancedcustomfields.com/\" rel=\"nofollow nor...
2017/01/02
[ "https://wordpress.stackexchange.com/questions/251007", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/33903/" ]
I need to replace featured images on pages with a video if certain posts contain a video from YouTube, Vimeo, other video hosting services allowed by WordPress. Here's the pseudo code that I want to use on a custom page: ``` if ( has_post_thumbnail( get_the_ID() { if has_video(pseudocode to check whether the sin...
Let's say for simplicity that you're using [ACF](https://www.advancedcustomfields.com/). You need to create a video link field once ACF is installed and assign it to posts. Then, in the post you want a video to show up, add the url. I usually assign this field as a text field and then have users enter the youtube id (l...
251,023
<p>Which is better...</p> <pre><code>&lt;?php if (is_page()): ?&gt; &lt;?php else: ?&gt; &lt;?php endif; ?&gt; </code></pre> <p>or</p> <pre><code>&lt;?php if (is_page()) { ?&gt; &lt;?php } else { ?&gt; &lt;?php } ?&gt; </code></pre>
[ { "answer_id": 251027, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 1, "selected": false, "text": "<p>I really don't know which is better. Exploring the different conditional statements syntax.</p>\n\n<p>I believe...
2017/01/02
[ "https://wordpress.stackexchange.com/questions/251023", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/37346/" ]
Which is better... ``` <?php if (is_page()): ?> <?php else: ?> <?php endif; ?> ``` or ``` <?php if (is_page()) { ?> <?php } else { ?> <?php } ?> ```
As far as I can tell, there's no performance difference. And both styles are acceptable by [WordPress Coding Standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#brace-style) as you can read in: > > Braces should always be used, even when they are not required: > > > and > > ...
251,025
<p>i would like to to add an AdSense activation code to my Wordpress site. </p> <p>Google says it needs to be inserted right AFTER the tag</p> <p>I have tried the plugin Snippets, yet it seems not to be working.</p> <p>The code is:</p> <pre><code>&lt;script async src="//pagead2.googlesyndication.com/pagead/js/adsb...
[ { "answer_id": 251029, "author": "Jami Gibbs", "author_id": 75524, "author_profile": "https://wordpress.stackexchange.com/users/75524", "pm_score": 2, "selected": false, "text": "<p>Without using a plugin, the WordPress way would be to use the <code>wp_head</code> action to insert the sc...
2017/01/02
[ "https://wordpress.stackexchange.com/questions/251025", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110060/" ]
i would like to to add an AdSense activation code to my Wordpress site. Google says it needs to be inserted right AFTER the tag I have tried the plugin Snippets, yet it seems not to be working. The code is: ``` <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"> </script> <script> (ad...
Without using a plugin, the WordPress way would be to use the `wp_head` action to insert the script and then enqueue the script file: ``` function mytextdomain_adsense() { $output=" <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: 'ca-pub-5316020100281676', enab...
251,032
<p>I am new to web design. </p> <p>I know how to use themes with wordpress.</p> <p>But I am interested in directly downloading the files from e.g. <a href="http://accesspressthemes.com/theme-demos/?theme=storevilla" rel="nofollow noreferrer">http://accesspressthemes.com/theme-demos/?theme=storevilla</a> and edit the ...
[ { "answer_id": 251029, "author": "Jami Gibbs", "author_id": 75524, "author_profile": "https://wordpress.stackexchange.com/users/75524", "pm_score": 2, "selected": false, "text": "<p>Without using a plugin, the WordPress way would be to use the <code>wp_head</code> action to insert the sc...
2017/01/02
[ "https://wordpress.stackexchange.com/questions/251032", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110062/" ]
I am new to web design. I know how to use themes with wordpress. But I am interested in directly downloading the files from e.g. <http://accesspressthemes.com/theme-demos/?theme=storevilla> and edit the contents using wordpress. How can I edit the downloaded files directly using wordpress?
Without using a plugin, the WordPress way would be to use the `wp_head` action to insert the script and then enqueue the script file: ``` function mytextdomain_adsense() { $output=" <script> (adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: 'ca-pub-5316020100281676', enab...
251,037
<p>I'm requesting posts with the WP REST API and need to sort them according to an ACF field. It's value represents a date (numeric, jQuery date format yymmdd). I know how to do it with a normal WP_Query and tried to do the same using the rest api:</p> <pre><code>mydomain.com/wp-json/wp/v2/posts?filter[orderby]=meta_v...
[ { "answer_id": 251047, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 3, "selected": true, "text": "<p>I'm guessing you haven't exposed meta_key and meta_value to the REST API with the rest_query_vars filter,...
2017/01/02
[ "https://wordpress.stackexchange.com/questions/251037", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/104835/" ]
I'm requesting posts with the WP REST API and need to sort them according to an ACF field. It's value represents a date (numeric, jQuery date format yymmdd). I know how to do it with a normal WP\_Query and tried to do the same using the rest api: ``` mydomain.com/wp-json/wp/v2/posts?filter[orderby]=meta_value_num&filt...
I'm guessing you haven't exposed meta\_key and meta\_value to the REST API with the rest\_query\_vars filter, so this should do it: ``` function my_add_meta_vars ($current_vars) { $current_vars = array_merge ($current_vars, array ('meta_key', 'meta_value')); return $current_vars; } add_filter ('rest_query_vars...
251,045
<p>Have allowed users to register their own website and at the same time this adds them as a user to that site.</p> <p>However, is there a way to default them to a subscriber of the site they are signing up for rather than automatically adding them as a administrator.</p> <p>I've looked around in the mess that is wp-...
[ { "answer_id": 251052, "author": "codiiv", "author_id": 91561, "author_profile": "https://wordpress.stackexchange.com/users/91561", "pm_score": 0, "selected": false, "text": "<p>You will need something like the <a href=\"https://en-ca.wordpress.org/plugins/multisite-user-role-manager/\" ...
2017/01/02
[ "https://wordpress.stackexchange.com/questions/251045", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109779/" ]
Have allowed users to register their own website and at the same time this adds them as a user to that site. However, is there a way to default them to a subscriber of the site they are signing up for rather than automatically adding them as a administrator. I've looked around in the mess that is wp-signup.php and wp...
Ok, so this isn't possible to do by default. As I already had a hook for `wpmu_activate_blog()` I just created another with a lower priority which will be fired after. This function also has the 2 parameters I need. So upon activation of the account I simply remove Admin role and set a new role based of the subscripti...
251,049
<p>The theme I am using places the menu next to the logo (see the attached image). But I prefer to have the menu under the logo. How can I do it? <a href="https://i.stack.imgur.com/HcHCa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HcHCa.png" alt="menu"></a></p>
[ { "answer_id": 251052, "author": "codiiv", "author_id": 91561, "author_profile": "https://wordpress.stackexchange.com/users/91561", "pm_score": 0, "selected": false, "text": "<p>You will need something like the <a href=\"https://en-ca.wordpress.org/plugins/multisite-user-role-manager/\" ...
2017/01/02
[ "https://wordpress.stackexchange.com/questions/251049", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110062/" ]
The theme I am using places the menu next to the logo (see the attached image). But I prefer to have the menu under the logo. How can I do it? [![menu](https://i.stack.imgur.com/HcHCa.png)](https://i.stack.imgur.com/HcHCa.png)
Ok, so this isn't possible to do by default. As I already had a hook for `wpmu_activate_blog()` I just created another with a lower priority which will be fired after. This function also has the 2 parameters I need. So upon activation of the account I simply remove Admin role and set a new role based of the subscripti...
251,076
<p>I recently made up simple Minecraft site about one starting server, instaled plugin called:Minestatus, and getting these errors. Exact same error for one other plugin. I am running <strong>WP <em>3.19.4</em></strong></p> <pre><code>Warning: Declaration of Minestatus_Widget::widget(array $args, $instance) should be ...
[ { "answer_id": 251078, "author": "prosti", "author_id": 88606, "author_profile": "https://wordpress.stackexchange.com/users/88606", "pm_score": 0, "selected": false, "text": "<p>The class you should extend may be better <code>Widget</code> not <code>Widgetize</code>.</p>\n\n<pre><code>cl...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251076", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110082/" ]
I recently made up simple Minecraft site about one starting server, instaled plugin called:Minestatus, and getting these errors. Exact same error for one other plugin. I am running **WP *3.19.4*** ``` Warning: Declaration of Minestatus_Widget::widget(array $args, $instance) should be compatible with WP_Widget::widget(...
Remove "array" from your arguments declaration: `public function widget(array $args, $instance)` should be `public function widget($args, $instance)`
251,081
<p>I'm not an expert at much, so please excuse me if this is an easy question... but it's got my head spinning.</p> <p>I have an archive template (adapted from a standard 'enfold' theme template) which I am using to display a simple list of books. Following a tutorial I found elsewhere, I created the loop below.</p> ...
[ { "answer_id": 251078, "author": "prosti", "author_id": 88606, "author_profile": "https://wordpress.stackexchange.com/users/88606", "pm_score": 0, "selected": false, "text": "<p>The class you should extend may be better <code>Widget</code> not <code>Widgetize</code>.</p>\n\n<pre><code>cl...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251081", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110085/" ]
I'm not an expert at much, so please excuse me if this is an easy question... but it's got my head spinning. I have an archive template (adapted from a standard 'enfold' theme template) which I am using to display a simple list of books. Following a tutorial I found elsewhere, I created the loop below. If I understan...
Remove "array" from your arguments declaration: `public function widget(array $args, $instance)` should be `public function widget($args, $instance)`
251,102
<p>Just another basic question of wordpress development. I have a custom post created using the functions.php on theme folder that I am currently developing. I simply want to display all post from it. </p> <pre><code>function people() { register_post_type( 'people', array( 'labels' =&gt; arra...
[ { "answer_id": 251078, "author": "prosti", "author_id": 88606, "author_profile": "https://wordpress.stackexchange.com/users/88606", "pm_score": 0, "selected": false, "text": "<p>The class you should extend may be better <code>Widget</code> not <code>Widgetize</code>.</p>\n\n<pre><code>cl...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251102", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110106/" ]
Just another basic question of wordpress development. I have a custom post created using the functions.php on theme folder that I am currently developing. I simply want to display all post from it. ``` function people() { register_post_type( 'people', array( 'labels' => array( ...
Remove "array" from your arguments declaration: `public function widget(array $args, $instance)` should be `public function widget($args, $instance)`
251,111
<p>i have tags, and for some tags i want to load a different stylesheet But i don't know how</p> <p>i have....</p> <pre><code>function customstyles() { if ( is_tag( 'circulair' ) ) { //Register and enqueue the stylesheet for tag-circulair. wp_register_style( 'tag-circulair', get_stylesheet_direct...
[ { "answer_id": 251078, "author": "prosti", "author_id": 88606, "author_profile": "https://wordpress.stackexchange.com/users/88606", "pm_score": 0, "selected": false, "text": "<p>The class you should extend may be better <code>Widget</code> not <code>Widgetize</code>.</p>\n\n<pre><code>cl...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251111", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109390/" ]
i have tags, and for some tags i want to load a different stylesheet But i don't know how i have.... ``` function customstyles() { if ( is_tag( 'circulair' ) ) { //Register and enqueue the stylesheet for tag-circulair. wp_register_style( 'tag-circulair', get_stylesheet_directory_uri() . '/layout-...
Remove "array" from your arguments declaration: `public function widget(array $args, $instance)` should be `public function widget($args, $instance)`
251,114
<p>I have a plugin that I do not want to be activated if it doesn't meet a certain WP version number then show error message in admin_notices action hook. As far as I have researched, the code below is the best that I can achieve this goal:</p> <pre><code>$wp_version = get_bloginfo('version'); if ( $wp_version &lt; 4....
[ { "answer_id": 251117, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 2, "selected": false, "text": "<p>Essentialy, you can not do it the way you want. All wordpress form are redirecting after completing their...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251114", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/60720/" ]
I have a plugin that I do not want to be activated if it doesn't meet a certain WP version number then show error message in admin\_notices action hook. As far as I have researched, the code below is the best that I can achieve this goal: ``` $wp_version = get_bloginfo('version'); if ( $wp_version < 4.5 ) { add_ac...
I may be late to this party, but to stop plugin activation and have WordPress show an error message where the admin notices go, I simply output an error message and terminate execution. This has the added advantage of playing nice with [wp-cli](https://wp-cli.org/): [![Plugin activation failed](https://i.stack.imgur.c...
251,115
<p>The logo is being requested over http rather than https.</p> <p>I assume this is the code affecting it:</p> <pre><code>&lt;?php echo esc_url( home_url( '/' ) ); ?&gt; </code></pre> <p>any advice would be appreciated</p>
[ { "answer_id": 251117, "author": "Mark Kaplun", "author_id": 23970, "author_profile": "https://wordpress.stackexchange.com/users/23970", "pm_score": 2, "selected": false, "text": "<p>Essentialy, you can not do it the way you want. All wordpress form are redirecting after completing their...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251115", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110112/" ]
The logo is being requested over http rather than https. I assume this is the code affecting it: ``` <?php echo esc_url( home_url( '/' ) ); ?> ``` any advice would be appreciated
I may be late to this party, but to stop plugin activation and have WordPress show an error message where the admin notices go, I simply output an error message and terminate execution. This has the added advantage of playing nice with [wp-cli](https://wp-cli.org/): [![Plugin activation failed](https://i.stack.imgur.c...
251,116
<p>I want to work with WordPress multisite, but I want to be able to use my own names. For example my main site is called <code>example.com</code>. If I want to add a new site to my multisite network it's gonna be called <code>newsite.example.com</code>. I want it to be <code>newsite.com</code> without <code>example</c...
[ { "answer_id": 251120, "author": "David", "author_id": 31323, "author_profile": "https://wordpress.stackexchange.com/users/31323", "pm_score": 3, "selected": false, "text": "<p>It was made possible without using a plugin a few releases ago (can't remember the concrete release but the fea...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251116", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/102796/" ]
I want to work with WordPress multisite, but I want to be able to use my own names. For example my main site is called `example.com`. If I want to add a new site to my multisite network it's gonna be called `newsite.example.com`. I want it to be `newsite.com` without `example`. Is there a way to achieve this? I heard...
There seems to always be a bit on confusion on this topic. Perhaps WordPress could do a better job guiding it's users in this process. Although, I suppose Multi-site wasn't intended to be used for TLD's. So first of all, I would [install WordPress](https://codex.wordpress.org/Installing_WordPress), [setup multisite](h...
251,121
<p>I am wondering how to make a Link "Go to first post" While I have opened some post?</p> <p>Any suggestion is welcome.</p> <p>Thank you.</p>
[ { "answer_id": 251125, "author": "Mostafa Soufi", "author_id": 106877, "author_profile": "https://wordpress.stackexchange.com/users/106877", "pm_score": 0, "selected": false, "text": "<p>Using bellow function in your theme for get first post link.</p>\n\n<pre><code>&lt;?php\nfunction get...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251121", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/101369/" ]
I am wondering how to make a Link "Go to first post" While I have opened some post? Any suggestion is welcome. Thank you.
I'll assume by "first" you mean "newest", since if it's the oldest, then all you'd need would be the url of that post. ``` $latest = get_posts(array('numberposts' => 1)); $url = get_permalink($latest[0]->ID); echo "<a href='" . $url . "'>Go to first post</a>"; ``` This should give you a link that always goes to what...
251,129
<p>I have tried ticking comments and discussion but still don't seem to have a comments box. Even went through and ticked individually for each post. Help!</p>
[ { "answer_id": 251125, "author": "Mostafa Soufi", "author_id": 106877, "author_profile": "https://wordpress.stackexchange.com/users/106877", "pm_score": 0, "selected": false, "text": "<p>Using bellow function in your theme for get first post link.</p>\n\n<pre><code>&lt;?php\nfunction get...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251129", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110119/" ]
I have tried ticking comments and discussion but still don't seem to have a comments box. Even went through and ticked individually for each post. Help!
I'll assume by "first" you mean "newest", since if it's the oldest, then all you'd need would be the url of that post. ``` $latest = get_posts(array('numberposts' => 1)); $url = get_permalink($latest[0]->ID); echo "<a href='" . $url . "'>Go to first post</a>"; ``` This should give you a link that always goes to what...
251,130
<p>I'm experiencing something really strange, that I just can't seem to figure out. I'm busy writing my own theme. It's nothing special or super advanced, just wanted a fun project and get a little custom. </p> <p>On the homepage, I want the posts displayed in a masonry style, pinterest clone card UI. I've set up the ...
[ { "answer_id": 251125, "author": "Mostafa Soufi", "author_id": 106877, "author_profile": "https://wordpress.stackexchange.com/users/106877", "pm_score": 0, "selected": false, "text": "<p>Using bellow function in your theme for get first post link.</p>\n\n<pre><code>&lt;?php\nfunction get...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251130", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110118/" ]
I'm experiencing something really strange, that I just can't seem to figure out. I'm busy writing my own theme. It's nothing special or super advanced, just wanted a fun project and get a little custom. On the homepage, I want the posts displayed in a masonry style, pinterest clone card UI. I've set up the HTML and t...
I'll assume by "first" you mean "newest", since if it's the oldest, then all you'd need would be the url of that post. ``` $latest = get_posts(array('numberposts' => 1)); $url = get_permalink($latest[0]->ID); echo "<a href='" . $url . "'>Go to first post</a>"; ``` This should give you a link that always goes to what...
251,132
<p>Is there a way to get posts from a custom taxonomy <strong>without specifying a term</strong>?</p> <p>I have a custom taxonomy called <code>media_category</code> and I want to get all the attachments which use this taxonomy since I have some attachments which doesnt use this taxonomy at all.</p>
[ { "answer_id": 251143, "author": "codiiv", "author_id": 91561, "author_profile": "https://wordpress.stackexchange.com/users/91561", "pm_score": 0, "selected": false, "text": "<p>You need to create a taxonomy archive by doing something like this: </p>\n\n<p>1) In the theme directory creat...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251132", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110123/" ]
Is there a way to get posts from a custom taxonomy **without specifying a term**? I have a custom taxonomy called `media_category` and I want to get all the attachments which use this taxonomy since I have some attachments which doesnt use this taxonomy at all.
You may do it by this method. --- ``` $media\_category = get\_terms('media\_category'); foreach($media\_category as $cat) { wp\_reset\_query(); $args = array('post\_type' => 'your\_post\_type', 'tax\_query' => array( array( 'taxonomy' => 'media\_category', 'field' => 'slug', 'terms' => $cat->slug, ), ), );...
251,140
<p>Is there a way to avoid WordPress "flattening" the category tree when a child category is selected?</p> <p>This applies to both custom taxonomies and WP's built in "category" taxonomy.</p> <p>To explain further, say I have the following category tree:</p> <pre><code>Parent Child Grandchild Another par...
[ { "answer_id": 251159, "author": "Leora Deans", "author_id": 94243, "author_profile": "https://wordpress.stackexchange.com/users/94243", "pm_score": 3, "selected": true, "text": "<p>I haven't fully tested this, but it may be helpful:\nCategories in Hierarchical Order plugin at <a href=\"...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251140", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/23714/" ]
Is there a way to avoid WordPress "flattening" the category tree when a child category is selected? This applies to both custom taxonomies and WP's built in "category" taxonomy. To explain further, say I have the following category tree: ``` Parent Child Grandchild Another parent Another child An...
I haven't fully tested this, but it may be helpful: Categories in Hierarchical Order plugin at <https://wordpress.org/plugins/categories-in-hierarchical-order/>
251,141
<p>I am using this css code on my theme in order to get the styling under an image in a post:</p> <pre><code>.wp-caption .wp-caption-text { font-size: 16px !important; color: #000000; text-align: center; background-color: #F2F2F2; padding-top: 1px; margin: 1px; } </code></pre> <p>When using ...
[ { "answer_id": 251155, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 0, "selected": false, "text": "<p>Here are the principles of what's probably going on. (Fixing it without guesswork would require access t...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251141", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109463/" ]
I am using this css code on my theme in order to get the styling under an image in a post: ``` .wp-caption .wp-caption-text { font-size: 16px !important; color: #000000; text-align: center; background-color: #F2F2F2; padding-top: 1px; margin: 1px; } ``` When using it on mobile, the text is ...
Please Use **font-size: 2.5vw;** it is responsive and set according to size. ``` .wp-caption .wp-caption-text { **font-size: 16px** !important; color: #000000; text-align: center; background-color: #F2F2F2; padding-top: 1px; margin: 1px; } ```
251,147
<p>I am creating an eBooks download website. There will be around 5000 eBooks. Each page/post will have a download link to the pdf file of the eBook. My question is, should I create 5000 pages or 5000 posts for these eBooks? </p>
[ { "answer_id": 251155, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 0, "selected": false, "text": "<p>Here are the principles of what's probably going on. (Fixing it without guesswork would require access t...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251147", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110129/" ]
I am creating an eBooks download website. There will be around 5000 eBooks. Each page/post will have a download link to the pdf file of the eBook. My question is, should I create 5000 pages or 5000 posts for these eBooks?
Please Use **font-size: 2.5vw;** it is responsive and set according to size. ``` .wp-caption .wp-caption-text { **font-size: 16px** !important; color: #000000; text-align: center; background-color: #F2F2F2; padding-top: 1px; margin: 1px; } ```
251,171
<p>So, I'm building a new theme based on Underscores. So far, I've managed to get ACF Pro to call different header files from a dropdwon selction in the Options page but, now I am faced with the task of determining how best to handle the css for each of the custom header files and how to load widget areas based on whic...
[ { "answer_id": 251178, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 0, "selected": false, "text": "<p>Yes your approach to loading header-specific CSS sounds fine. You could do something like this in functi...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251171", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110141/" ]
So, I'm building a new theme based on Underscores. So far, I've managed to get ACF Pro to call different header files from a dropdwon selction in the Options page but, now I am faced with the task of determining how best to handle the css for each of the custom header files and how to load widget areas based on which h...
That's not how you use `get_theme_file_uri();` You need to specify the directory RELATIVE to your currently active theme's directory. So for example, if your currently activated theme is `rm-acf1`, and all of your custom header CSS files are located in the subfolder `hdr-styles`. * This is your theme directory: `...
251,175
<p>Hi is there anybody who can help me how to find all posts without category and assign the "Uncategorized"? I have more than 7000 posts and 300 of them are without category, how I could assing one?</p> <p>And another question, how I can assign category to all posts (except bulk edit which doesnt work well with this ...
[ { "answer_id": 251209, "author": "CodeMascot", "author_id": 44192, "author_profile": "https://wordpress.stackexchange.com/users/44192", "pm_score": 1, "selected": false, "text": "<p>If you don't set any category to your post then it'll automatically be assigned to <strong>Uncategorized</...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251175", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/64771/" ]
Hi is there anybody who can help me how to find all posts without category and assign the "Uncategorized"? I have more than 7000 posts and 300 of them are without category, how I could assing one? And another question, how I can assign category to all posts (except bulk edit which doesnt work well with this amount of ...
The current accepted takes posts out of range too. Since it LEFT JOIN on wp\_term\_relationships without knowing that the first join might be a Category or a Post\_tag, it gives false-positive, hence affecting posts that might not be without category. Inspired from the current accepted answer, change the "37" for your...
251,177
<p>I want to ask a question: I have a source code, it only works for the post-new, but not edit post. So how to disable Publish button on Edit post if post title exists?</p> <pre><code>add_action('wp_ajax_check-posts-by-title', function(){ $title = isset( $_REQUEST['title'] ) ? esc_attr( $_REQUEST['title'] ) : nul...
[ { "answer_id": 251209, "author": "CodeMascot", "author_id": 44192, "author_profile": "https://wordpress.stackexchange.com/users/44192", "pm_score": 1, "selected": false, "text": "<p>If you don't set any category to your post then it'll automatically be assigned to <strong>Uncategorized</...
2017/01/03
[ "https://wordpress.stackexchange.com/questions/251177", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109872/" ]
I want to ask a question: I have a source code, it only works for the post-new, but not edit post. So how to disable Publish button on Edit post if post title exists? ``` add_action('wp_ajax_check-posts-by-title', function(){ $title = isset( $_REQUEST['title'] ) ? esc_attr( $_REQUEST['title'] ) : null; // chec...
The current accepted takes posts out of range too. Since it LEFT JOIN on wp\_term\_relationships without knowing that the first join might be a Category or a Post\_tag, it gives false-positive, hence affecting posts that might not be without category. Inspired from the current accepted answer, change the "37" for your...
251,260
<p>I have a custom theme that for the latest posts displays the posts thumbnail. What I am looking to do is to check and if there is no thumbnail set then use the category's featured image. I could upload the images and use this:</p> <pre><code>if (!$photo) : $uploads = wp_upload_dir(); $photo = '&lt;d...
[ { "answer_id": 251206, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 0, "selected": false, "text": "<p>Going to cover several bases in my answer. :)</p>\n\n<p>If you are creating your own theme, and want to ...
2017/01/04
[ "https://wordpress.stackexchange.com/questions/251260", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110131/" ]
I have a custom theme that for the latest posts displays the posts thumbnail. What I am looking to do is to check and if there is no thumbnail set then use the category's featured image. I could upload the images and use this: ``` if (!$photo) : $uploads = wp_upload_dir(); $photo = '<div class="related...
Don't forget that Wordpress was primarily designed to be a blogging CMS, so when it comes to theme development, developers often opt for a non-standard approach in exchange for the potential for more features. Theme developers have three options when they approach this, one of which (#2 below) you mentioned. 1. Direc...
251,278
<p>I'm using the <a href="https://wordpress.org/plugins/json-api-user/" rel="nofollow noreferrer">JSON REST User plugin</a> which extends <a href="https://wordpress.org/plugins/json-api/" rel="nofollow noreferrer">JSON REST Api</a>. I'm sending http data to-from the api up to 4 times back to back in some cases which is...
[ { "answer_id": 251282, "author": "Nathan Crause", "author_id": 81384, "author_profile": "https://wordpress.stackexchange.com/users/81384", "pm_score": 0, "selected": false, "text": "<p>This comes down to a server configuration - if you have enabled \"allow_url_fopen\" in your php.ini you...
2017/01/04
[ "https://wordpress.stackexchange.com/questions/251278", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/13170/" ]
I'm using the [JSON REST User plugin](https://wordpress.org/plugins/json-api-user/) which extends [JSON REST Api](https://wordpress.org/plugins/json-api/). I'm sending http data to-from the api up to 4 times back to back in some cases which is dragging network performance. How can I call `http://localhost/wp-json/fb_...
You can internally route REST API requests using [`rest_do_request`](https://developer.wordpress.org/reference/functions/rest_do_request/) and a [`WP_REST_Request` object](https://developer.wordpress.org/reference/classes/wp_rest_request/). ``` $request = new WP_REST_Request( 'GET', '/fb_connect' ); $request->set_para...
251,295
<p>I have a situation where it would be ideal to have the database on separate hosting. Just because the host of the current site does not offer mysql. I cannot move the site (for a company)</p> <p>Can I install wordpress on current hosting in a sub domain and have the database on another host? I have never used anyth...
[ { "answer_id": 251297, "author": "jdm2112", "author_id": 45202, "author_profile": "https://wordpress.stackexchange.com/users/45202", "pm_score": 2, "selected": false, "text": "<p>Yes - absolutely. Simply enter the appropriate hostname and credentials in wp-config.php. Instead of the ...
2017/01/04
[ "https://wordpress.stackexchange.com/questions/251295", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110222/" ]
I have a situation where it would be ideal to have the database on separate hosting. Just because the host of the current site does not offer mysql. I cannot move the site (for a company) Can I install wordpress on current hosting in a sub domain and have the database on another host? I have never used anything except...
Yes - absolutely. Simply enter the appropriate hostname and credentials in wp-config.php. Instead of the default `localhost` use the hostname provided by your database provider. Example: ``` define( 'DB_HOST', 'mysql.example.com:3307' ); ``` <https://codex.wordpress.org/Editing_wp-config.php#Set_Database_Host>
251,298
<p>Ok, i've tried all day long and do not know, how this can be. I have a website on which i load jquery like that:</p> <pre><code>function my_script_loader() { if (!is_admin()) { // only load for front end //Clear jQuery if already registered wp_deregister_script('jquery'); wp_register_script('jquery', "h...
[ { "answer_id": 251301, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 2, "selected": true, "text": "<p>As <strong>Mark Kaplun</strong> said in the comments, something is adding <code>defer</code> to your one ...
2017/01/04
[ "https://wordpress.stackexchange.com/questions/251298", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/71669/" ]
Ok, i've tried all day long and do not know, how this can be. I have a website on which i load jquery like that: ``` function my_script_loader() { if (!is_admin()) { // only load for front end //Clear jQuery if already registered wp_deregister_script('jquery'); wp_register_script('jquery', "http" . ($_SERV...
As **Mark Kaplun** said in the comments, something is adding `defer` to your one domain's script. If you want your subdomain jQuery script to also have `defer`, this should do it: ``` function my_add_defer ($tag, $handle, $src) { if ($handle == 'jquery') { return str_replace (' src=', ' defer="defer" src=...
251,324
<p>I have the following code, and I am attempting to concatenate the values of the echo html code &amp; 'the_meta'. Can anyone please suggest an edit to code to get this working?</p> <p><strong>CURRENT CODE</strong></p> <pre><code>&lt;?php echo '&lt;p style="text-align:left;font-size:18px;margin-bottom:5px;"&gt; &lt;...
[ { "answer_id": 251325, "author": "Coffee coder", "author_id": 103155, "author_profile": "https://wordpress.stackexchange.com/users/103155", "pm_score": 0, "selected": false, "text": "<p>Did you try adding echo \"\"; inside the tag like this:</p>\n\n<pre><code> &lt;?php the_meta(echo \"so...
2017/01/04
[ "https://wordpress.stackexchange.com/questions/251324", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/91067/" ]
I have the following code, and I am attempting to concatenate the values of the echo html code & 'the\_meta'. Can anyone please suggest an edit to code to get this working? **CURRENT CODE** ``` <?php echo '<p style="text-align:left;font-size:18px;margin-bottom:5px;"> <span style="color: #000000;">By AUTHOR FOR</span>...
To display `the_meta ()` after the 'by author for' text just needs a small change: ``` <p style="text-align:left;font-size:18px;margin-bottom:5px;"><span style="color: #000000;">By AUTHOR FOR</span> <?php the_meta (); ?></p> ``` However I'm not sure you want to use `the_meta ()`, because all values get displayed, an...
251,347
<p>Greeting Community,</p> <p><strong>Here’s my challenge:</strong> We have an annual report that is published annually. We do <em>NOT</em> want to spin up a new site and domain each year, but house each previous year’s edition on the same site. </p> <p><strong><em>The kicker is this —</em></strong> each year has a u...
[ { "answer_id": 251360, "author": "Ben HartLenn", "author_id": 6645, "author_profile": "https://wordpress.stackexchange.com/users/6645", "pm_score": 1, "selected": false, "text": "<p>One simple solution that might meet your needs would be to add the published year of the current post or p...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251347", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/143628/" ]
Greeting Community, **Here’s my challenge:** We have an annual report that is published annually. We do *NOT* want to spin up a new site and domain each year, but house each previous year’s edition on the same site. ***The kicker is this —*** each year has a unique design but most of the site’s functionality and fea...
One simple solution that might meet your needs would be to add the published year of the current post or page to your body using body\_class(), and then add the appropriate styles for each year to your stylesheet. Here I add a new css class to the html `<body>` element like ".year-2016" using `get_the_date()` to fill ...
251,377
<p>I'm kind lost on how to do that. Let me explain my problem.</p> <p>I have an admin who can define a lot of categories. Then i want him to be able to attribute through the dashboard multiple categories to each user.</p> <p>Then when a user will make a post (custom post type: news and others, using both the same tax...
[ { "answer_id": 251380, "author": "CodeMascot", "author_id": 44192, "author_profile": "https://wordpress.stackexchange.com/users/44192", "pm_score": 0, "selected": false, "text": "<p>Here is your solution-</p>\n\n<pre><code>add_action( 'save_post_news', 'the_dramatist_save_post_cat', 10, ...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251377", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110272/" ]
I'm kind lost on how to do that. Let me explain my problem. I have an admin who can define a lot of categories. Then i want him to be able to attribute through the dashboard multiple categories to each user. Then when a user will make a post (custom post type: news and others, using both the same taxonomy "Categories...
Ok thanks for your help i manage to make it work : 1 : When admin go inside user option page he can select wich categories he is into 2 : Then this user is creating a news and we can see i'm hiding the category box 3 : Then if we check we can see the news has the categories set from the one choose in the user [![1](h...
251,390
<p>I have a simple webpage with a dropdown menu with a few options. I would like to be able to get the user's selection and then output the same selection on the webpage. This is the code I have so far.</p> <pre><code>\\Pretty standard code for getting the header and title and &lt;\div&gt; etc. &lt;select id="animal" ...
[ { "answer_id": 251402, "author": "AddWeb Solution Pvt Ltd", "author_id": 73643, "author_profile": "https://wordpress.stackexchange.com/users/73643", "pm_score": -1, "selected": false, "text": "<p>You can use below way to display dropdown for selected value.</p>\n\n<pre><code>&lt;script&g...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251390", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110016/" ]
I have a simple webpage with a dropdown menu with a few options. I would like to be able to get the user's selection and then output the same selection on the webpage. This is the code I have so far. ``` \\Pretty standard code for getting the header and title and <\div> etc. <select id="animal" name="animal"> ...
How about this: ``` <?php $arr = ["Cat", "Dog", "Cow" ]; if( $_POST['animal']){ $animal=$_POST['animal']; echo $animal; } ?> <form name="f" id="a" method="post" action=""> <select id="animal" name="animal" onchange="this.form.submit()" > <option value="0">--Select Animal--</optio...
251,408
<p>theme: functions.php</p> <pre><code>function one_admin_menu() { add_menu_page( 'One Dashboard', 'One', 'manage_options', 'one_menu', 'one_menu_url', 'dashicons-admin-site', 1 ); } add_action( 'admin_menu', 'one_admin_menu' ); function one_menu_url...
[ { "answer_id": 254312, "author": "dev", "author_id": 111997, "author_profile": "https://wordpress.stackexchange.com/users/111997", "pm_score": -1, "selected": false, "text": "<p>get_template_directory_url</p>\n\n<p>no </p>\n\n<p>get_template_directory_uri</p>\n" }, { "answer_id":...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251408", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110286/" ]
theme: functions.php ``` function one_admin_menu() { add_menu_page( 'One Dashboard', 'One', 'manage_options', 'one_menu', 'one_menu_url', 'dashicons-admin-site', 1 ); } add_action( 'admin_menu', 'one_admin_menu' ); function one_menu_url() { inclu...
Please check your domain. In my case url is like this. [http://xxx.local/wp-content/themes/{your\_teme}](http://xxx.local/wp-content/themes/%7Byour_teme%7D) change to <http://xxx.local/> It fixed. Sometimes wrong url cause this problem.
251,425
<p>When an Administrator for a sub site removes a user from their sub site, I am trying to not only remove the user, but also completely delete them from the entire MU site. I have tried this:</p> <pre><code>add_action( 'remove_user_from_blog', 'custom_remove_user', 10,4 ); function custom_remove_user( $user_id ) { ...
[ { "answer_id": 251432, "author": "prosti", "author_id": 88606, "author_profile": "https://wordpress.stackexchange.com/users/88606", "pm_score": 0, "selected": false, "text": "<blockquote>\n <p>If I input an actual number of an existing user, the function works properly.</p>\n</blockquot...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251425", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/32828/" ]
When an Administrator for a sub site removes a user from their sub site, I am trying to not only remove the user, but also completely delete them from the entire MU site. I have tried this: ``` add_action( 'remove_user_from_blog', 'custom_remove_user', 10,4 ); function custom_remove_user( $user_id ) { wpmu_delete...
The function you are looking for is `wpmu_delete_user($user->ID)` I wrote a small plugin to delete users across the whole network by role: ``` <?php /** * Plugin Name: Regbox Delete multisite users * Plugin URI: http://www.regbox.se/delete-multisite-users * Description: Delete users by role across network * Versi...
251,429
<p>Is it possible to set default options for inserting image into article. I want every image to link to full image and be right aligned. Setting this manually every time is annoying and unproductive.</p> <p>Can I do this with some hook in my functions file?</p>
[ { "answer_id": 251437, "author": "Khaled Allen", "author_id": 110308, "author_profile": "https://wordpress.stackexchange.com/users/110308", "pm_score": 3, "selected": true, "text": "<p>You can do this in two ways. If you want to keep it theme specific, edit your <code>functions.php</code...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251429", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/105920/" ]
Is it possible to set default options for inserting image into article. I want every image to link to full image and be right aligned. Setting this manually every time is annoying and unproductive. Can I do this with some hook in my functions file?
You can do this in two ways. If you want to keep it theme specific, edit your `functions.php` file with this code: ``` add_action( 'after_setup_theme', 'my_new_default_image_settings' ); function my_new_default_image_settings() { update_option( 'image_default_align', 'right' ); update_option( 'image_default_l...
251,439
<p>We often see this insdie the WordPress templates: </p> <pre><code>while ( have_posts() ) : the_post(); ... endwhile; </code></pre> <p>Do you have any idea why not using braces or "curly brackets" {} for <code>while</code> loop? What is the gain?</p>
[ { "answer_id": 251441, "author": "iguanarama", "author_id": 109807, "author_profile": "https://wordpress.stackexchange.com/users/109807", "pm_score": 0, "selected": false, "text": "<p>It's just another way of writing it, mostly a stylistic choice. I use while loops with curly brackets, a...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251439", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/88606/" ]
We often see this insdie the WordPress templates: ``` while ( have_posts() ) : the_post(); ... endwhile; ``` Do you have any idea why not using braces or "curly brackets" {} for `while` loop? What is the gain?
According to the wordpress handbook on [**php coding standards**](https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/), braces should be used for all blocks in the style shown below: ``` if ( condition ) { action1(); action2(); } elseif ( condition2 && condition3 ) { action3(); ...
251,458
<p>I use an extension called Custom Field Suite to import info from a csv in order to batch create posts. In order to display the form fields I use <code>&lt;?php echo CFS()-&gt;get('image_location'); ?&gt;</code> One type of information I import is image sources which I display images using <code>&lt;img src="&lt;?php...
[ { "answer_id": 251459, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 2, "selected": false, "text": "<p>You can format it as, there's also no need to put the <code>echo</code></p>\n\n<pre><code>&lt;?php next_post_li...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251458", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/70344/" ]
I use an extension called Custom Field Suite to import info from a csv in order to batch create posts. In order to display the form fields I use `<?php echo CFS()->get('image_location'); ?>` One type of information I import is image sources which I display images using `<img src="<?php echo CFS()->get('image_location')...
You can format it as, there's also no need to put the `echo` ``` <?php next_post_link('%link',"<img src=" . CFS()->get('image_location') . "/>"); ?> ``` `CFS()->get('image_location')` gets the field based on the current post id. If you want to use it for the next or previous, you have to pass the next or previous po...
251,460
<p>I'm trying to make posts as easy to edit as possible. When a person clicks on "Edit Post", the default is to open in the same window. This can be frustrating, because it's a little difficult to quickly get back to the page they clicked "Edit Post" from (the blogroll).</p> <p>Obviously, they could right-click > "Ope...
[ { "answer_id": 251462, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 3, "selected": true, "text": "<p>You can adjust the link via the <code>edit_post_link</code> filter.</p>\n\n<p>Here's an example where we use a...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251460", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/73966/" ]
I'm trying to make posts as easy to edit as possible. When a person clicks on "Edit Post", the default is to open in the same window. This can be frustrating, because it's a little difficult to quickly get back to the page they clicked "Edit Post" from (the blogroll). Obviously, they could right-click > "Open Link in ...
You can adjust the link via the `edit_post_link` filter. Here's an example where we use a simple replace since we don't have the `class` and `url` explicitly as input arguments: ``` add_filter( 'edit_post_link', function( $link, $post_id, $text ) { // Add the target attribute if( false === strpos( $link, 'ta...
251,461
<p>I am trying to get the exact same hierarchy structure of this site: <a href="https://theculturetrip.com/" rel="nofollow noreferrer">https://theculturetrip.com/</a></p> <p>To me it seems they have this category hierarchy:</p> <pre><code>-Continent ——-Country ————–City -Food and Drink -See and Do -Art -Literature -e...
[ { "answer_id": 251462, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 3, "selected": true, "text": "<p>You can adjust the link via the <code>edit_post_link</code> filter.</p>\n\n<p>Here's an example where we use a...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251461", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110322/" ]
I am trying to get the exact same hierarchy structure of this site: <https://theculturetrip.com/> To me it seems they have this category hierarchy: ``` -Continent ——-Country ————–City -Food and Drink -See and Do -Art -Literature -etc. ``` If you click on a continent you will land on a page with posts in that contin...
You can adjust the link via the `edit_post_link` filter. Here's an example where we use a simple replace since we don't have the `class` and `url` explicitly as input arguments: ``` add_filter( 'edit_post_link', function( $link, $post_id, $text ) { // Add the target attribute if( false === strpos( $link, 'ta...
251,468
<p>How would I go about displaying related categories instead of the follow which displays related tags. Please any help would be much appreciated. Thanks in advance</p> <pre><code>if(!function_exists('solstice_related_post')) { function solstice_related_post() { global $post; $tags = wp_get_post_...
[ { "answer_id": 251462, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 3, "selected": true, "text": "<p>You can adjust the link via the <code>edit_post_link</code> filter.</p>\n\n<p>Here's an example where we use a...
2017/01/05
[ "https://wordpress.stackexchange.com/questions/251468", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110255/" ]
How would I go about displaying related categories instead of the follow which displays related tags. Please any help would be much appreciated. Thanks in advance ``` if(!function_exists('solstice_related_post')) { function solstice_related_post() { global $post; $tags = wp_get_post_tags($post->ID)...
You can adjust the link via the `edit_post_link` filter. Here's an example where we use a simple replace since we don't have the `class` and `url` explicitly as input arguments: ``` add_filter( 'edit_post_link', function( $link, $post_id, $text ) { // Add the target attribute if( false === strpos( $link, 'ta...
251,499
<p>I have a code like this.</p> <pre><code>&lt;div class="slick"&gt;&lt;/div&gt; &lt;div class="slick active"&gt;&lt;/div&gt; &lt;div class="slick active"&gt;&lt;/div&gt; &lt;div class="slick active"&gt;&lt;/div&gt; &lt;div class="slick"&gt;&lt;/div&gt; &lt;div class="slick"&gt;&lt;/div&gt; </code></pre> <p>I want to...
[ { "answer_id": 251500, "author": "Shareef", "author_id": 110271, "author_profile": "https://wordpress.stackexchange.com/users/110271", "pm_score": 0, "selected": false, "text": "<p>with the help of jQuery you can achieve it.</p>\n\n<p>jQuery will find the last child of the parent and giv...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251499", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110342/" ]
I have a code like this. ``` <div class="slick"></div> <div class="slick active"></div> <div class="slick active"></div> <div class="slick active"></div> <div class="slick"></div> <div class="slick"></div> ``` I want to style the last div having the class 'active'. Is there any way to do this?
There is no (good) way to solve this problem in its current state with CSS. The best solution is to add an extra class to the last active div, or to use javascript See [this question](https://stackoverflow.com/questions/6401268/how-do-i-select-the-last-child-with-a-specific-class-name-in-css) for more details
251,521
<p>I created a menu to my Wordpress website, and I have a menu like this</p> <pre><code> MENU1 ..submenu2 ...submenu3 </code></pre> <p>if I click on submenu3/submenu2 then the URL is like,</p> <pre><code> abc.com/submenu3 or abc.com/submenu2 </code></pre> <p>what I exactly want to do is like, </p> <pre><code>...
[ { "answer_id": 251532, "author": "pankaj", "author_id": 110363, "author_profile": "https://wordpress.stackexchange.com/users/110363", "pm_score": -1, "selected": false, "text": "<p>Assign MENU1 as parent of submenu2 &amp; submenu2 as parent of submenu3</p>\n" }, { "answer_id": 25...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251521", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/106371/" ]
I created a menu to my Wordpress website, and I have a menu like this ``` MENU1 ..submenu2 ...submenu3 ``` if I click on submenu3/submenu2 then the URL is like, ``` abc.com/submenu3 or abc.com/submenu2 ``` what I exactly want to do is like, ``` abc.com/menu1/submenu2/submenu3 ``` Please reply me your ...
If you dont want to do any back end coding you can create a custom link in the menu panel [![enter image description here](https://i.stack.imgur.com/XXrHJ.jpg)](https://i.stack.imgur.com/XXrHJ.jpg) and then drag the submenu3 under the msubmenu2 and then all under menu1 [![enter image description here](https://i.stac...
251,527
<p>I have been meddling with REST API and I am stuck with this: How can I filter posts in both cat1 and cat2?</p> <p>For now, <code>?categories[]=45&amp;categories[]=50</code> returns in category ID 45 OR 50 - how can I get posts in 45 AND 50?</p> <p>Thanks in advance.</p>
[ { "answer_id": 252483, "author": "Jamie Halvorson", "author_id": 82990, "author_profile": "https://wordpress.stackexchange.com/users/82990", "pm_score": -1, "selected": false, "text": "<p>You should be able to access multiple categories by using the following:</p>\n\n<pre><code>http://YO...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251527", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110359/" ]
I have been meddling with REST API and I am stuck with this: How can I filter posts in both cat1 and cat2? For now, `?categories[]=45&categories[]=50` returns in category ID 45 OR 50 - how can I get posts in 45 AND 50? Thanks in advance.
Multiple categories can be separated by comma like below ``` http://example.com/wp-json/wp/v2/posts?categories=20,30 ``` hope this helps
251,530
<p>My function in functions.php</p> <pre><code>function adding_front_style(){ if(is_front_page()){ wp_enqueue_style('front',get_template_directory_uri().'/css/front.css'); }else{ //some code } } add_action('init','adding_front_style'); </code></pre> <p>My front-page.php</p> <pre><code>&lt;?php get_header(); ?&...
[ { "answer_id": 251534, "author": "Yuvrajsinh Jhala", "author_id": 110365, "author_profile": "https://wordpress.stackexchange.com/users/110365", "pm_score": 2, "selected": true, "text": "<p>Wrong choice of hook, <code>Init</code> hook Fires after WordPress has finished loading, so what yo...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251530", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110362/" ]
My function in functions.php ``` function adding_front_style(){ if(is_front_page()){ wp_enqueue_style('front',get_template_directory_uri().'/css/front.css'); }else{ //some code } } add_action('init','adding_front_style'); ``` My front-page.php ``` <?php get_header(); ?> <div class = "search"> <?php get_sear...
Wrong choice of hook, `Init` hook Fires after WordPress has finished loading, so what you have thought is right. But `wp_enqueue_scripts` hook is required to load JavaScript and CSS. Replace line `add_action('init','adding_front_style');` with `add_action('wp_enqueue_scripts','adding_front_style');`
251,531
<p>The menus have been registered in <code>functions.php</code>, but they don't appear within the Appearance > Menus section in Admin and the pages, posts etc options are greyed out.</p> <p>The menus are saved, as you can not create the menu with the same name again.</p> <p><a href="https://i.stack.imgur.com/29ekB.pn...
[ { "answer_id": 251534, "author": "Yuvrajsinh Jhala", "author_id": 110365, "author_profile": "https://wordpress.stackexchange.com/users/110365", "pm_score": 2, "selected": true, "text": "<p>Wrong choice of hook, <code>Init</code> hook Fires after WordPress has finished loading, so what yo...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251531", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/69398/" ]
The menus have been registered in `functions.php`, but they don't appear within the Appearance > Menus section in Admin and the pages, posts etc options are greyed out. The menus are saved, as you can not create the menu with the same name again. [![Greyed out Menu options](https://i.stack.imgur.com/29ekB.png)](https...
Wrong choice of hook, `Init` hook Fires after WordPress has finished loading, so what you have thought is right. But `wp_enqueue_scripts` hook is required to load JavaScript and CSS. Replace line `add_action('init','adding_front_style');` with `add_action('wp_enqueue_scripts','adding_front_style');`
251,576
<p>On my <a href="http://alexander-pastor.de" rel="nofollow noreferrer" title="my website">website</a> I want to mark featured articles with a star icon, which works by checking if a post has the category "Featured". However, it somehow always seems to return true for backdated articles, which is really strange. (Every...
[ { "answer_id": 251577, "author": "montrealist", "author_id": 8105, "author_profile": "https://wordpress.stackexchange.com/users/8105", "pm_score": 0, "selected": false, "text": "<p>I suspect that you're not using <code>get_posts</code> correctly (looks like you're mixing <code>WP_Query</...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251576", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/92039/" ]
On my [website](http://alexander-pastor.de "my website") I want to mark featured articles with a star icon, which works by checking if a post has the category "Featured". However, it somehow always seems to return true for backdated articles, which is really strange. (Everything below Computers -> Programming Best Prac...
you do not reset the icon variable after each iteration of the loop, therefor once it gets to be a "star" it will always remain.
251,580
<p>I'm trying to use <code>setcookie</code> inside a WP REST request, but it isn't working. The REST request runs properly and performs it's other duties well, but it doesn't set any cookies. </p> <p>Here's my example code, which is running on <code>mywebsite.com</code></p> <pre><code>add_action( 'rest_api_init', fun...
[ { "answer_id": 251582, "author": "rorymorris89", "author_id": 104431, "author_profile": "https://wordpress.stackexchange.com/users/104431", "pm_score": 3, "selected": true, "text": "<p>Adding this line to my <code>$.ajax</code> call fixed the problem for me.</p>\n\n<pre><code>$.ajax({\n ...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251580", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/104431/" ]
I'm trying to use `setcookie` inside a WP REST request, but it isn't working. The REST request runs properly and performs it's other duties well, but it doesn't set any cookies. Here's my example code, which is running on `mywebsite.com` ``` add_action( 'rest_api_init', function () { register_rest_route( 'my_aut...
Adding this line to my `$.ajax` call fixed the problem for me. ``` $.ajax({ xhrFields: { withCredentials: true }, // the rest... ``` Sidenote: this requires the following header to be set on the server-side, which is enabled by default with the REST API (it seems). ``` Access-Control-Allow-Credentials:true ...
251,587
<p>I have the following array that I want to store in a single custom field.</p> <pre><code>array("Accounting"=&gt;"Peter", "Finance"=&gt;"Ben", "Marketing"=&gt;"Joe"); </code></pre> <p>I want to store it by typing it in a custom field in wp-admin.</p> <p>Then I want to retrieve this custom field as an array in a pa...
[ { "answer_id": 251589, "author": "Ray", "author_id": 101989, "author_profile": "https://wordpress.stackexchange.com/users/101989", "pm_score": 3, "selected": true, "text": "<p>You can <code>json_encode()</code> it which will make it a string that you can put into a custom field then just...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251587", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110297/" ]
I have the following array that I want to store in a single custom field. ``` array("Accounting"=>"Peter", "Finance"=>"Ben", "Marketing"=>"Joe"); ``` I want to store it by typing it in a custom field in wp-admin. Then I want to retrieve this custom field as an array in a page, with something like ``` $pos = get_po...
You can `json_encode()` it which will make it a string that you can put into a custom field then just ensure you `json_decode()` it to bring it back to an object or `json_decode($data, true)` to bring it back as an array ``` $arr = array("Accounting"=>"Peter", "Finance"=>"Ben", "Marketing"=>"Joe"); update_post_meta($p...
251,592
<p>I want to move the title of the posts under the thumbnail of the post while keeping all 3 of the posts on the same row. This seems like a fairly easy thing to do, but I can't figure out the correct coding. If anyone could help I would really appreciate it.</p> <p>image of what it looks like (I want the post title b...
[ { "answer_id": 251589, "author": "Ray", "author_id": 101989, "author_profile": "https://wordpress.stackexchange.com/users/101989", "pm_score": 3, "selected": true, "text": "<p>You can <code>json_encode()</code> it which will make it a string that you can put into a custom field then just...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251592", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/101743/" ]
I want to move the title of the posts under the thumbnail of the post while keeping all 3 of the posts on the same row. This seems like a fairly easy thing to do, but I can't figure out the correct coding. If anyone could help I would really appreciate it. image of what it looks like (I want the post title below the i...
You can `json_encode()` it which will make it a string that you can put into a custom field then just ensure you `json_decode()` it to bring it back to an object or `json_decode($data, true)` to bring it back as an array ``` $arr = array("Accounting"=>"Peter", "Finance"=>"Ben", "Marketing"=>"Joe"); update_post_meta($p...
251,594
<p>I have a WordPress site with an SSL certificate. It all works fine, except that this little insecure shield icon shows up because the header has an enqueued non-https script. <a href="https://i.stack.imgur.com/99FiS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/99FiS.png" alt="enter image descr...
[ { "answer_id": 251597, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": false, "text": "<p>There is no filter when a script is registered, so it is hard to track that down. Use a full text search in all your ...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251594", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110395/" ]
I have a WordPress site with an SSL certificate. It all works fine, except that this little insecure shield icon shows up because the header has an enqueued non-https script. [![enter image description here](https://i.stack.imgur.com/99FiS.png)](https://i.stack.imgur.com/99FiS.png) The issue is that I don't know which...
There is no filter when a script is registered, so it is hard to track that down. Use a full text search in all your theme and plugin files to find the source. In addition, you can filter the URL before it is printed: ``` add_filter( 'script_loader_src', function( $url ) { if ( 0 !== strpos( $url, 'http:' ) ) ...
251,605
<p>I have a custom post type that has a number of meta boxes in it. One of these is an expiration_date field that stores its info in the db as a string formatted like </p> <pre><code>Feb 1, 2017 </code></pre> <p>I am trying to write a query that will filter out those items that have a date in the past, only showing f...
[ { "answer_id": 255915, "author": "Stephen", "author_id": 11023, "author_profile": "https://wordpress.stackexchange.com/users/11023", "pm_score": 1, "selected": false, "text": "<p>I ended up working around the problem of the initial date format by changing the expiration_date field format...
2017/01/06
[ "https://wordpress.stackexchange.com/questions/251605", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/11023/" ]
I have a custom post type that has a number of meta boxes in it. One of these is an expiration\_date field that stores its info in the db as a string formatted like ``` Feb 1, 2017 ``` I am trying to write a query that will filter out those items that have a date in the past, only showing future ones. I have tried ...
Introducing `STR_TO_DATE` ------------------------- MySQL has a [`STR_TO_DATE`](https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date) function that you could leverage for the scope. To use it you need to filter the `WHERE` clause of a `WP_Query`, probably using [`posts_where`](htt...
251,614
<p>I am working on a script to detect if the user is close enough to our location to display the local version of our website located on a subdomain. I'm looking for help where I should insert this and the best method of redirection from WordPress</p> <pre><code>&lt;?php $ip = $_SERVER['REMOTE_ADDR']; $details = json_...
[ { "answer_id": 251615, "author": "czerspalace", "author_id": 47406, "author_profile": "https://wordpress.stackexchange.com/users/47406", "pm_score": 0, "selected": false, "text": "<p>In the functions.php file of your theme, I would add an action that hooks to template_redirect, like this...
2017/01/07
[ "https://wordpress.stackexchange.com/questions/251614", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110382/" ]
I am working on a script to detect if the user is close enough to our location to display the local version of our website located on a subdomain. I'm looking for help where I should insert this and the best method of redirection from WordPress ``` <?php $ip = $_SERVER['REMOTE_ADDR']; $details = json_decode(file_get_c...
If you want it to run as early as possible, which makes sense if you want to avoid loading unnecessary assets, put the code in a function in a [Must Use Plugin](https://codex.wordpress.org/Must_Use_Plugins), and hook that function to the [`muplugins_loaded`](https://codex.wordpress.org/Plugin_API/Action_Reference/muplu...
251,618
<p>This is work: <a href="http://localhost:8888/all-games?s=me" rel="nofollow noreferrer">http://localhost:8888/all-games?s=me</a></p> <p>This doesn't work (page cannot be found): <a href="http://localhost:8888/all-games?s=met" rel="nofollow noreferrer">http://localhost:8888/all-games?s=met</a></p> <p>the post title ...
[ { "answer_id": 251619, "author": "tonywei", "author_id": 110409, "author_profile": "https://wordpress.stackexchange.com/users/110409", "pm_score": 0, "selected": false, "text": "<p>change 's' parameter into something else, like \"search\", example: </p>\n\n<p><a href=\"http://localhost:8...
2017/01/07
[ "https://wordpress.stackexchange.com/questions/251618", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110409/" ]
This is work: <http://localhost:8888/all-games?s=me> This doesn't work (page cannot be found): <http://localhost:8888/all-games?s=met> the post title is: Metal Gear Solid here is my query: ``` $args = array("posts_per_page" => get_option("posts_per_page"), "post_type" => "astro_game", "paged" => get...
You should use [**`get_query_var`**](https://developer.wordpress.org/reference/functions/get_query_var/) instead of `$_GET["s"]`, this is a built-in wordpress function that retrieves **public** query variables which would have already been parsed and fed into WP\_Query. ``` $args = array("posts_per_page" => get_option...
251,620
<p>Function:</p> <pre><code>function get_highest_bid(){ global $wpdb; $postid = get_post_id(); $table = $wpdb-&gt;prefix . "jwp_bids"; $highest_bid = $wpdb-&gt;get_var( "Select max(bid_amt) FROM " . $table . " WHERE post_id = " . $postid . ';" );' echo $highest_bid; } </code...
[ { "answer_id": 251619, "author": "tonywei", "author_id": 110409, "author_profile": "https://wordpress.stackexchange.com/users/110409", "pm_score": 0, "selected": false, "text": "<p>change 's' parameter into something else, like \"search\", example: </p>\n\n<p><a href=\"http://localhost:8...
2017/01/07
[ "https://wordpress.stackexchange.com/questions/251620", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/108215/" ]
Function: ``` function get_highest_bid(){ global $wpdb; $postid = get_post_id(); $table = $wpdb->prefix . "jwp_bids"; $highest_bid = $wpdb->get_var( "Select max(bid_amt) FROM " . $table . " WHERE post_id = " . $postid . ';" );' echo $highest_bid; } ``` Error: Unexpected ec...
You should use [**`get_query_var`**](https://developer.wordpress.org/reference/functions/get_query_var/) instead of `$_GET["s"]`, this is a built-in wordpress function that retrieves **public** query variables which would have already been parsed and fed into WP\_Query. ``` $args = array("posts_per_page" => get_option...
251,648
<p>I have a parent theme that refers to an image in the theme's <code>img</code> folder like so;</p> <pre><code>&lt;button id="buy" type="submit"&gt;&lt;img src="&lt;?php bloginfo('template_directory'); ?&gt;/img/Buy-Now-Button.jpg" border="0" width="160" height="47" title="" alt="Buy One" style="cursor:pointer;"&gt;&...
[ { "answer_id": 251650, "author": "Felix", "author_id": 110428, "author_profile": "https://wordpress.stackexchange.com/users/110428", "pm_score": 3, "selected": true, "text": "<p>Try using <code>get_stylesheet_directory_uri()</code> instead of <code>bloginfo('template_directory')</code>.<...
2017/01/07
[ "https://wordpress.stackexchange.com/questions/251648", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/36773/" ]
I have a parent theme that refers to an image in the theme's `img` folder like so; ``` <button id="buy" type="submit"><img src="<?php bloginfo('template_directory'); ?>/img/Buy-Now-Button.jpg" border="0" width="160" height="47" title="" alt="Buy One" style="cursor:pointer;"></button> ``` However, I thought that if I...
Try using `get_stylesheet_directory_uri()` instead of `bloginfo('template_directory')`. This function will give you the path to the `style.css` of your currently activated theme (the child theme). From there you can navigate to all sub-folders in your child theme folder. ``` <button id="buy" type="submit"><img src="<...
251,652
<p>I just want some information about WP_DEBUG.</p> <p>What happen if I comment this line in wp-config.php files</p> <pre><code>define('WP_DEBUG',true); </code></pre> <p>I had an issue on the site where my server getting down and database where crashing, so my server guy advice me that, this comment code is causing ...
[ { "answer_id": 251658, "author": "Dohnutt", "author_id": 110437, "author_profile": "https://wordpress.stackexchange.com/users/110437", "pm_score": 0, "selected": false, "text": "<p>Setting <code>WP_DEBUG</code> to <code>true</code> will show that you have errors on your website, but shou...
2017/01/07
[ "https://wordpress.stackexchange.com/questions/251652", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/104250/" ]
I just want some information about WP\_DEBUG. What happen if I comment this line in wp-config.php files ``` define('WP_DEBUG',true); ``` I had an issue on the site where my server getting down and database where crashing, so my server guy advice me that, this comment code is causing issue on the server and the data...
IMHO WP\_DEBUG allows to enable display of notices during development. If you look at the core file `default-constants.php` you see this : ``` if ( !defined('WP_DEBUG') ) define( 'WP_DEBUG', false ); ``` So I don't see why you should set it to false *again* in `wp-config.php`. Regarding your issue just delete ...
251,661
<p>Okay, so when I include my header in any page besides the home page, and I inspect the page, all of the calls show as errors because it's adding that page to the root of the source call. How do I change that?? Here are some of my calls:</p> <pre><code>&lt;script src="wp-content/themes/gamer_meld/js/jquery.flexslide...
[ { "answer_id": 251662, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 1, "selected": true, "text": "<p>First, don't put script tags directly in template files, enqueue them from your theme/child theme's <code>functions...
2017/01/07
[ "https://wordpress.stackexchange.com/questions/251661", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/108586/" ]
Okay, so when I include my header in any page besides the home page, and I inspect the page, all of the calls show as errors because it's adding that page to the root of the source call. How do I change that?? Here are some of my calls: ``` <script src="wp-content/themes/gamer_meld/js/jquery.flexslider.js"></script> <...
First, don't put script tags directly in template files, enqueue them from your theme/child theme's `functions.php`. Second, use the API to output URIs for scripts, don't hardcode or use relative paths. ``` function wpdocs_theme_name_scripts() { wp_enqueue_script( 'flexslider', get_template_directo...
251,676
<p>I am migrating from an ancient static web site to Wordpress.</p> <p>In the old site, I used htaccess and RewriteRule to simplify URLs and mask the underlying parms. One case was:</p> <pre><code>RewriteRule ^definition/([^/]+) /display-definition?word=$1 [NC] </code></pre> <p>This allowed people to specify a URL o...
[ { "answer_id": 251662, "author": "Milo", "author_id": 4771, "author_profile": "https://wordpress.stackexchange.com/users/4771", "pm_score": 1, "selected": true, "text": "<p>First, don't put script tags directly in template files, enqueue them from your theme/child theme's <code>functions...
2017/01/07
[ "https://wordpress.stackexchange.com/questions/251676", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110445/" ]
I am migrating from an ancient static web site to Wordpress. In the old site, I used htaccess and RewriteRule to simplify URLs and mask the underlying parms. One case was: ``` RewriteRule ^definition/([^/]+) /display-definition?word=$1 [NC] ``` This allowed people to specify a URL of: ``` domain.com/definition/lov...
First, don't put script tags directly in template files, enqueue them from your theme/child theme's `functions.php`. Second, use the API to output URIs for scripts, don't hardcode or use relative paths. ``` function wpdocs_theme_name_scripts() { wp_enqueue_script( 'flexslider', get_template_directo...
251,678
<p>I have some custom PHP that creates a shortcode. I must have some errant code in here because it is showing up on the backend (edit side) of Wordpress. I am using the Divi theme and have it in a Text module with a class "SearchBarArea". So that is the name of the DIV it should be in, but on the front end, it is NOT ...
[ { "answer_id": 251679, "author": "CompuSolver", "author_id": 110446, "author_profile": "https://wordpress.stackexchange.com/users/110446", "pm_score": 1, "selected": false, "text": "<p>Even with the missing open php tag, this won't work the way you're trying to do it. The Divi code modu...
2017/01/07
[ "https://wordpress.stackexchange.com/questions/251678", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110216/" ]
I have some custom PHP that creates a shortcode. I must have some errant code in here because it is showing up on the backend (edit side) of Wordpress. I am using the Divi theme and have it in a Text module with a class "SearchBarArea". So that is the name of the DIV it should be in, but on the front end, it is NOT in ...
Even with the missing open php tag, this won't work the way you're trying to do it. The Divi code module accepts html code and PHP shortcodes. I haven't tried javascript, so not sure about that. You'll need to integrate your code as a stand alone plugin. After that, you can use the shortcode in the Divi code module an...
251,696
<p>Here is what I have so far:</p> <pre><code>function get_highest_bid_info(){ global $wpdb; $postid = get_the_id(); $table = $wpdb-&gt;prefix . "jwp_bids"; $wpdb-&gt;get_results( "SELECT email, max(bid_amt) FROM $table WHERE post_id = '$postid')" ); </code></pre> <p>N...
[ { "answer_id": 251679, "author": "CompuSolver", "author_id": 110446, "author_profile": "https://wordpress.stackexchange.com/users/110446", "pm_score": 1, "selected": false, "text": "<p>Even with the missing open php tag, this won't work the way you're trying to do it. The Divi code modu...
2017/01/08
[ "https://wordpress.stackexchange.com/questions/251696", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/108215/" ]
Here is what I have so far: ``` function get_highest_bid_info(){ global $wpdb; $postid = get_the_id(); $table = $wpdb->prefix . "jwp_bids"; $wpdb->get_results( "SELECT email, max(bid_amt) FROM $table WHERE post_id = '$postid')" ); ``` Now I want to assign those two va...
Even with the missing open php tag, this won't work the way you're trying to do it. The Divi code module accepts html code and PHP shortcodes. I haven't tried javascript, so not sure about that. You'll need to integrate your code as a stand alone plugin. After that, you can use the shortcode in the Divi code module an...
251,702
<p>In my single wordpress posts I want to apply a padding of 100px to the left and right. The problem is that when I apply it to .single .post-content the images also get a padding. However, I want all of the images on the posts pages to be set to 100%. Is there a way to separate the actual body text and the images? T...
[ { "answer_id": 251679, "author": "CompuSolver", "author_id": 110446, "author_profile": "https://wordpress.stackexchange.com/users/110446", "pm_score": 1, "selected": false, "text": "<p>Even with the missing open php tag, this won't work the way you're trying to do it. The Divi code modu...
2017/01/08
[ "https://wordpress.stackexchange.com/questions/251702", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/101743/" ]
In my single wordpress posts I want to apply a padding of 100px to the left and right. The problem is that when I apply it to .single .post-content the images also get a padding. However, I want all of the images on the posts pages to be set to 100%. Is there a way to separate the actual body text and the images? This ...
Even with the missing open php tag, this won't work the way you're trying to do it. The Divi code module accepts html code and PHP shortcodes. I haven't tried javascript, so not sure about that. You'll need to integrate your code as a stand alone plugin. After that, you can use the shortcode in the Divi code module an...
251,719
<p>Is it possible to install WordPress on a public server that doesn't have a domain name configured yet? I thought I'd set it up on IP-only, and had the line <code>server_name _;</code> in my Nginx configuration. I think it's because of this that the WordPress installation dies at <code>wp-admin/install.php?step=2</co...
[ { "answer_id": 251720, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": true, "text": "<p>Set <code>server_name</code> to the IP address, eg:</p>\n\n<pre><code>server {\n listen 80;\n server_name 0.1....
2017/01/08
[ "https://wordpress.stackexchange.com/questions/251719", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/57726/" ]
Is it possible to install WordPress on a public server that doesn't have a domain name configured yet? I thought I'd set it up on IP-only, and had the line `server_name _;` in my Nginx configuration. I think it's because of this that the WordPress installation dies at `wp-admin/install.php?step=2` and I see the followi...
Set `server_name` to the IP address, eg: ``` server { listen 80; server_name 0.1.2.3; // other stuff } ``` You could also leave it out, because the default in ngninx is an empty string. But then all those pieces in WordPress that don't validate `$_SERVER['SERVER_NAME']` and similar values … will just b...
251,735
<p>I am trying to <a href="https://wordpress.stackexchange.com/questions/56884/how-to-only-hook-on-single-php-after-content">use this method</a> to include a template part (HTML Code) rather than using some plain text. When I use text, it shows correctly below the content with the the_content filter. However, If I try ...
[ { "answer_id": 251720, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": true, "text": "<p>Set <code>server_name</code> to the IP address, eg:</p>\n\n<pre><code>server {\n listen 80;\n server_name 0.1....
2017/01/08
[ "https://wordpress.stackexchange.com/questions/251735", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/43332/" ]
I am trying to [use this method](https://wordpress.stackexchange.com/questions/56884/how-to-only-hook-on-single-php-after-content) to include a template part (HTML Code) rather than using some plain text. When I use text, it shows correctly below the content with the the\_content filter. However, If I try to get\_templ...
Set `server_name` to the IP address, eg: ``` server { listen 80; server_name 0.1.2.3; // other stuff } ``` You could also leave it out, because the default in ngninx is an empty string. But then all those pieces in WordPress that don't validate `$_SERVER['SERVER_NAME']` and similar values … will just b...
251,746
<p>I'd like to get the closest post to today's post; yes, I checked and search this topic and found the code working for me:</p> <pre><code>date_default_timezone_set("Europe/Warsaw"); setlocale(LC_ALL, en_GB); $year = strftime('%Y'); $month = strftime('%m'); $day = strftime('%e'); //$hour = strftime('%k'); if($month &...
[ { "answer_id": 251720, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": true, "text": "<p>Set <code>server_name</code> to the IP address, eg:</p>\n\n<pre><code>server {\n listen 80;\n server_name 0.1....
2017/01/08
[ "https://wordpress.stackexchange.com/questions/251746", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/102644/" ]
I'd like to get the closest post to today's post; yes, I checked and search this topic and found the code working for me: ``` date_default_timezone_set("Europe/Warsaw"); setlocale(LC_ALL, en_GB); $year = strftime('%Y'); $month = strftime('%m'); $day = strftime('%e'); //$hour = strftime('%k'); if($month < 10) { $mo...
Set `server_name` to the IP address, eg: ``` server { listen 80; server_name 0.1.2.3; // other stuff } ``` You could also leave it out, because the default in ngninx is an empty string. But then all those pieces in WordPress that don't validate `$_SERVER['SERVER_NAME']` and similar values … will just b...
251,755
<p>I setup a single directory/ multiple sites WordPress Setup. And it worked as well. For some time. It still works but for one problem. The image upload doesn't work properly.</p> <p>I'll explain.</p> <p>Setup:- 1. One master directory containing full WordPress installation. 2. One directory for client site - lets ...
[ { "answer_id": 251720, "author": "fuxia", "author_id": 73, "author_profile": "https://wordpress.stackexchange.com/users/73", "pm_score": 2, "selected": true, "text": "<p>Set <code>server_name</code> to the IP address, eg:</p>\n\n<pre><code>server {\n listen 80;\n server_name 0.1....
2017/01/08
[ "https://wordpress.stackexchange.com/questions/251755", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/106155/" ]
I setup a single directory/ multiple sites WordPress Setup. And it worked as well. For some time. It still works but for one problem. The image upload doesn't work properly. I'll explain. Setup:- 1. One master directory containing full WordPress installation. 2. One directory for client site - lets say client1. Here...
Set `server_name` to the IP address, eg: ``` server { listen 80; server_name 0.1.2.3; // other stuff } ``` You could also leave it out, because the default in ngninx is an empty string. But then all those pieces in WordPress that don't validate `$_SERVER['SERVER_NAME']` and similar values … will just b...
251,776
<p>I've got some problems with templates in Wordpress (multisite). I've created a file in the root of my child-theme folder (template-test.php) </p> <pre><code>&lt;?php /** * Template Name: Test template * */ ?&gt; &lt;?php get_header(); ?&gt; &lt;?php get_footer(); ?&gt; </code></pre> <p>This template is not show...
[ { "answer_id": 251779, "author": "Levi", "author_id": 103404, "author_profile": "https://wordpress.stackexchange.com/users/103404", "pm_score": 1, "selected": false, "text": "<p>Templates can be deactivated by unsetting them from the <code>wp_themes</code> global variable before the temp...
2017/01/08
[ "https://wordpress.stackexchange.com/questions/251776", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/89977/" ]
I've got some problems with templates in Wordpress (multisite). I've created a file in the root of my child-theme folder (template-test.php) ``` <?php /** * Template Name: Test template * */ ?> <?php get_header(); ?> <?php get_footer(); ?> ``` This template is not showing up in the templates dropdown when creati...
Just in Wordpress 4.9 there's this bug: <https://core.trac.wordpress.org/ticket/42573> causing the template files to only be rescanned once every hour. To fix (until they release a new WP version with this changed), download the patch on that bug ticket and make the changes from the patch to `wp-includes/class-wp-them...
251,789
<p>I prevent WordPress from generating <code>thumbnail</code>, <code>medium</code>, and <code>large</code> image sizes for images I upload to the Media Library, by setting their dimensions to <code>0</code> from the dashboard: <code>Settings -&gt; Media</code> panel.</p> <p>I have also gotten rid of all instances of <...
[ { "answer_id": 251810, "author": "birgire", "author_id": 26350, "author_profile": "https://wordpress.stackexchange.com/users/26350", "pm_score": 4, "selected": false, "text": "<p>To remove the <code>medium_large</code> image size you can try to remove it with the <a href=\"https://devel...
2017/01/09
[ "https://wordpress.stackexchange.com/questions/251789", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/110512/" ]
I prevent WordPress from generating `thumbnail`, `medium`, and `large` image sizes for images I upload to the Media Library, by setting their dimensions to `0` from the dashboard: `Settings -> Media` panel. I have also gotten rid of all instances of `add_image_size` and `set_post_thumbnail_size` from the `functions.ph...
To remove the `medium_large` image size you can try to remove it with the [`intermediate_image_sizes`](https://developer.wordpress.org/reference/hooks/intermediate_image_sizes/) filter: ``` add_filter( 'intermediate_image_sizes', function( $sizes ) { return array_filter( $sizes, function( $val ) { retu...
251,825
<p>Strangely I don't find much sources on the web talking about my desires. So I hope it is a trivial thing I'm asking (although I fear it's not and Wordpress is just..).</p> <p>Naturally I need custom fields in my custom post types.</p> <p>Wordpress' native way of handling custom fields is very inconvenient and I ca...
[ { "answer_id": 251832, "author": "LWS-Mo", "author_id": 88895, "author_profile": "https://wordpress.stackexchange.com/users/88895", "pm_score": 2, "selected": false, "text": "<p>I think you are looking for \"meta boxes\".</p>\n\n<p>You will work with <code>add_meta_box()</code> to <stron...
2017/01/09
[ "https://wordpress.stackexchange.com/questions/251825", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/102487/" ]
Strangely I don't find much sources on the web talking about my desires. So I hope it is a trivial thing I'm asking (although I fear it's not and Wordpress is just..). Naturally I need custom fields in my custom post types. Wordpress' native way of handling custom fields is very inconvenient and I can't expect my cli...
I found a totally customizable solution. The general approach illustrated by LWS-mo remains the same. But instead of using `add_meta_box()` I used **`add_post_meta()`** `add_meta_box()` requires a callback function that prints out the HTML. Using `add_post_meta()` a callback has to be hooked in manually. The key acti...
251,841
<p>I'm using PHP handlebars templates and would like to keep all of the HTML in the template file so I don't have a header.php but rather the handlebars looks like </p> <pre><code>&lt;html&gt; &lt;head&gt; {{#wpHead}} &lt;/head&gt; </code></pre> <p>where wpHead is a helper that has nothing but <code>wp_head()...
[ { "answer_id": 251889, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 2, "selected": false, "text": "<p>You can use PHP's output buffering. WIth this you can write a wrapper for the <strong><code>get_head()</code></...
2017/01/09
[ "https://wordpress.stackexchange.com/questions/251841", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/31352/" ]
I'm using PHP handlebars templates and would like to keep all of the HTML in the template file so I don't have a header.php but rather the handlebars looks like ``` <html> <head> {{#wpHead}} </head> ``` where wpHead is a helper that has nothing but `wp_head();` but the output comes first before the `<html>`...
Thanks to @Tunji's answer, I accomplished this with a more generic function: ``` /** * Use output buffering to convert a function that echoes * to a return string instead */ function echo_to_string( $function ) { ob_start(); call_user_func( $function ); $html = ob_get_contents(); ob_end_cle...
251,865
<p>Is there a way to append Javascript to the body in the script tag without using a file? Normally you would do it with </p> <pre><code>wp_enqueue_script('name', 'path/to/js/file'); </code></pre> <p>Is there a way to include js in the script tag directly?<br> Like:</p> <pre><code>&lt;script&gt;My awesome code &l...
[ { "answer_id": 251873, "author": "Benoti", "author_id": 58141, "author_profile": "https://wordpress.stackexchange.com/users/58141", "pm_score": 3, "selected": true, "text": "<p>Yes, you can directly insert what you want in the header or the footer using the action <a href=\"https://codex...
2017/01/09
[ "https://wordpress.stackexchange.com/questions/251865", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/102247/" ]
Is there a way to append Javascript to the body in the script tag without using a file? Normally you would do it with ``` wp_enqueue_script('name', 'path/to/js/file'); ``` Is there a way to include js in the script tag directly? Like: ``` <script>My awesome code </script> ```
Yes, you can directly insert what you want in the header or the footer using the action [`wp_head`](https://codex.wordpress.org/Function_Reference/wp_head) or `wp_footer` ``` add_action('wp_head', 'custom_script'); function custom_script(){ ?> <script>My awesome code </script> <?php } ``` You onl...
251,866
<p>I'm building a custom carousel for a client. I've got a function which gets blocks of three images from all of the images attached to a post:</p> <pre><code>global $rental; $images = get_children( array( 'post_parent' =&gt; $rental_id, 'post_status' =&gt; 'inherit', 'post_type' =&gt; 'attachment', ...
[ { "answer_id": 251871, "author": "Tunji", "author_id": 54764, "author_profile": "https://wordpress.stackexchange.com/users/54764", "pm_score": 2, "selected": true, "text": "<p>You should be able to rewrite what you have about and also use <a href=\"https://developer.wordpress.org/referen...
2017/01/09
[ "https://wordpress.stackexchange.com/questions/251866", "https://wordpress.stackexchange.com", "https://wordpress.stackexchange.com/users/109355/" ]
I'm building a custom carousel for a client. I've got a function which gets blocks of three images from all of the images attached to a post: ``` global $rental; $images = get_children( array( 'post_parent' => $rental_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'im...
You should be able to rewrite what you have about and also use [**`get_permalink`**](https://developer.wordpress.org/reference/functions/get_permalink/) as [@Benoti](https://wordpress.stackexchange.com/users/58141/benoti) stated while omitting the `$split` array. > > [**`get_permalink`**](https://developer.wordpress....