INSTRUCTION
stringlengths 11
999
| RESPONSE
stringlengths 0
999
| SOURCE
stringlengths 16
38
| METADATA
dict |
---|---|---|---|
How to let the role "editor" to control the menu?
How to let the role "editor" to control the menu the only code i found was
$role_object = get_role( 'editor' );
but i couldn't use it | Add this to your **functions.php**
// Allow editors to see Appearance menu
$role_object = get_role( 'editor' );
$role_object->add_cap( 'edit_theme_options' );
function hide_menu() {
// Hide theme selection page
remove_submenu_page( 'themes.php', 'themes.php' );
// Hide widgets page
remove_submenu_page( 'themes.php', 'widgets.php' );
// Hide customize page
global $submenu;
unset($submenu['themes.php'][6]);
}
add_action('admin_head', 'hide_menu');
Source | stackexchange-wordpress | {
"answer_score": -1,
"question_score": 0,
"tags": "menus, admin menu"
} |
Site shows URL instead of "meta title" after deleted few plugins (not any SEO plugin was deleted)
www.Pifeed.net
after i deleted some useless plugins due to load-time issues the blog pages show url instead of title tag, though meta title tag is there in source code..
thanks for answers | your title tag is inside the script tag. It must be placed outside script. So you have to close the script tag for "adsbygoogle". | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, title, seo, blog page"
} |
POEDIT - Continue with translations
I'm translating my web from English. I already found some .po and .mo translations in my language, but translations are not completed, so some texts are still in English.
Thing is, that when I open already translated .po file, every message there is translated, but total count of messages is 160. When I open original english .po file, there are more than 220 messages.
This probably means, that I need to add remaining 60 messages into my translated file, and translate it.
Can you please tell me how ?
I don't want to translate whole thing again, when I need just 60 messages
Thank you so much! | You can edit .po files in text editor. Structure is very simple (some header, do not touch it) and a number of translations like that:
#: 404.php:21
msgid "Sorry! Page Not Found !"
msgstr ""
You can ignore comments started with #.
msgid - string how it appears in php code
msgstr - translation (if empty, msgid string will be shown on site)
You can find and simply copy 60 sets of 3 strings each from English .po to your-language .po by text editor. Then open poeditor and tranlate new 60 strings, or even simply do this job in text editor. You will need poedit only to create a new .mo from your .po file. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "translation"
} |
WordPress debug messages not displaying
WordPress is not displaying any errors / debug messages, even though I double- and triple-checked every setting.
**In php.ini, I have**
`error_reporting = E_ALL & ~E_NOTICE display_errors = On display_startup_errors = On log_errors = On track_errors = On`
**In wp-config.php, I have:**
`define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', true); @ini_set('display_errors', 1); error_reporting(E_ALL^E_NOTICE); `
Still, no errors are displayed at all. I verified that it is not a general PHP issue by testing it with an erroneous php file, like this: `<?php askdjh akjdsh ?>`. The error was displayed correctly. | The problem was caused by a plugin (wp-spamfree), which simply set `error_reporting(0)`.
So if anyone has the same problem, my advice is to search your whole `wp-content/plugins` directory for words like `error_reporting`, `display_errors` and similar to find out if any of your plugins tamper with these settings.
You can either disable these plugins, or fix it yourself for now and let the developers know that they should not do this.
**Fixes:**
1. One way to fix this is to simply remove the unwanted `error_reporting(0)`.
2. However, if you want to make sure that the plugin won't display any errors (which I think is stupid), another way would be to replace `error_reporting(0)` with `$errlvl = error_reporting(0);`.
This will save your current, desired error reporting level in `$errlvl`. The function will be executed with `error_reporting = 0`. At the end of the function you can then reset it back to the previous, desired level by calling `error_reporting($errlvl);`. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugin development, errors, debug, wp debug"
} |
Remove   from the_excerpt
Wordpress is creating a   in the_excerpt. How do I remove it?
<div class="subtitulo-noticia"><?php the_excerpt(); ?></div>
 and it should take care of it.
//* Remove non-breaking space from beginning of paragraph
add_filter( 'the_excerpt', function( $excerpt ) {
return str_replace( [ '<p> ', '<p> ' ], '<p>', $excerpt );
}, 999, 1 ); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "php, html, excerpt"
} |
Linking to the most recent post in a Custom Post Type
I found this wonderful code that allows you to create a link to the most recent post in a category, and it's perfect for what I need. I tried it out, it works great. However, it doesn't include posts from Custom Post Types. (I'm using Wordpress Pods plugin < to create my CPTs.) How do I modify this to include the posts from my custom post types? Any help is appreciated. Thanks!!
Original thread: How can I link to the most recent post in a category? | As long as Pods creates standard custom post types, you can simply update the arguments passed to WP_Query . The`$post_type` parameter will allow you to filter the results based on the specified post type (string) or post types (array).
$latest = new WP_Query( array(
'category_name' => $request->query_vars['category_name'],
'posts_per_page' => 1,
'post_type' => array ( 'post', 'your_custom_post_type' ),
) ); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "custom post types, wp query, categories, links, pods framework"
} |
Add wrapper to only youtube videos via embed_oembed_html filter function
I have a filter working to wrap embed_oembed links in a responsive wrapper. See code.
add_filter('embed_oembed_html', 'wrap_embed_with_div', 10, 3);
function wrap_embed_with_div($html, $url, $attr) {
return '<div class="responsive-container">'.$html.'</div>';
}
The only problem is this also applies to everything else on the oembed list, i.e, twitter embeds, instagram, etc. I was trying to add an if statement, but have no luck. Basically, it would be great to just add this wrapper to video embeds like youtube/vimeo. Here is what I got so far.
add_filter('embed_oembed_html', 'wrap_embed_with_div', 10, 3);
function wrap_embed_with_div($html, $url, $attr) {
if ($url == '
return '<div class="responsive-container">'.$html.'</div>';
}
else {
return $html;
}
} | `$url` will contain the full URL to the embed source. E.g.: ` so you have to search within `$url` to see if the provider's name appears:
add_filter( 'embed_oembed_html', 'wpse_embed_oembed_html', 99, 4 );
function wpse_embed_oembed_html( $cache, $url, $attr, $post_ID ) {
$classes = array();
// Add these classes to all embeds.
$classes_all = array(
'responsive-container',
);
// Check for different providers and add appropriate classes.
if ( false !== strpos( $url, 'vimeo.com' ) ) {
$classes[] = 'vimeo';
}
if ( false !== strpos( $url, 'youtube.com' ) ) {
$classes[] = 'youtube';
}
$classes = array_merge( $classes, $classes_all );
return '<div class="' . esc_attr( implode( ' ', $classes ) ) . '">' . $cache . '</div>';
} | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 3,
"tags": "filters, oembed"
} |
Get content and send to 3rd party
I've been asked to create a WordPress plugin that will basically show a button on the "edit" and the "new" pages of the admin panel which (when clicking the button) verify an API key (which you can set in the settings) and then send the post contents to a 3rd party.
When the 3rd party receives the text, they'll do their work on it and send it back through email to the website owner.
Now, the question is:
How do I get that button on the WP-admin on the new and edit pages of WordPress, is it even possible to get the current post's content, and send it to the 3rd party?
I'd love to hear if this is feasible (since I don't know what WordPress is capable of) and if so, if you could send me in the right direction. | absolutely it is possible.
function add_property_import_meta_box()
{
add_meta_box('property-import-images', 'Property Actions', 'function_import_images_metabox', 'property', 'side', 'high');
}
add_action('add_meta_boxes', 'add_property_import_meta_box');
function function_import_images_metabox($post)
{
// Noncename needed to verify where the data originated
echo '<input type="hidden" name="property_actions_nonce" id="property_actions_nonce" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
?>
<p><a href="/wp-admin/admin.php?page=actionhere" class="button button-primary button-large">Second Action</a></p>
<p><a href="/wp-admin/admin.php?page=actionhere" class="button button-primary button-large">Third Action</a></p>
<?php }
More info < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins, posts, plugin development, pages, admin"
} |
What does Wordpress do if I save a post without content/title?
I've created (as part of a theme) a few metaboxes for my post type. The metaboxes allow the user to interact with different instances of tinyMCE. Everything is working as it should, however, I can't for the life of me figure out which hook to use for publishing a post that is missing a title/content.
I've had a look at `/wp-includes/post.php` and was not able to find what I am looking for.
My question is: What happens when I click "Publish" when the post is missing content and a title? I know it gets created and is set as a "Draft" but it doesn't run the `save_post` hook. I'd also like to mention that I've tried using `new_to_draft`.
I've attempted using `draft_post` but I assume that because this is probably "auto-draft" it may not work (I have also tried "auto-draft_post").
add_action( 'save_post', array(__CLASS__, 'savePost'));
static public function savePost($post_id) {
echo 'hello';
} | Ever since the solution mentioned here, WP has been updated and now allows you to manipulate the save process of `wp_insert_post`. If you look at the lines 3035 to 3057 (WP 4.7) the result of the check for empty title and content is stored in `$maybe_empty`. This variable is then run through a filter called `wp_insert_post_empty_content`. If that filter returns something that evaluates to 'true' the save process is halted. So you could have it return false to overrule the check for emptiness:
add_filter ('wp_insert_post_empty_content', function() { return false; });
**Update**. Note that post information is passed to the filter as well, so you can write a more sophisticated filter, for instance checking for the post type before deciding to return true or false, or impose a maximum length on the title, and so on. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "posts, theme development, hooks, actions"
} |
Show author bio box
I have post page with author info. But I want to show author box info only if author has description. this is what i tried to do:
<?php if ( !empty(get_the_author_meta('description')) and !empty( get_the_author_meta( 'ID' )) ):?>
<div class="blog-article-author">
//author info here
</div>
<?php endif; ?>
But I get an error:
> Can't use function return value in write context
for this part of code :
<?php if ( !empty(get_the_author_meta('description')) and !empty( get_the_author_meta( 'ID' )) ):?>
How to solve this problem ? | Try this one :
<?php
$authordesc = get_the_author_meta( 'description' );
if ( ! empty ( $authordesc ) ){ ?>
<div class="blog-article-author">
//author info here...
</div>
<?php } ?> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, functions, loop"
} |
How can I remove the search window?
How can I remove the search window? I have searched and tried everything to no avail. The theme I'm using is BlankSlate.
 doesn't appear when logged-out, but I'd still like to get rid of it if I can.
I searched through all the files in the theme for the word "search" and tried removing that command from `entry.php` and `entry-summary.php`. None of that had an effect. I also tried removing the `search.php` file, that had no effect. I also tried adding:
form.search-form { display: none; }
Into the `style.css` page. Also no change. | > I searched through all the files in the theme for the word "search" and tried removing that command from `entry.php` and `entry-summary.php`. None of that had an effect. I also tried removing the `search.php` file, that had no effect.
To save you grief, any edits to the core files provided by WordPress will potentially break your website if you modify it incorrectly. Also with each new update provided by WordPress, it will overwrite and re-add the files to their default/updated state.
To hide the search, add the following to your child theme's `function.php`:
add_action( 'wp_before_admin_bar_render', 'wpse_254662_toolbar', 10, 1 );
function wpse_254662_toolbar() {
# Hide search from admin toolbar
global $wp_admin_bar;
$wp_admin_bar -> remove_menu( 'search' );
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "search"
} |
Need to show featured service boxes on my company website
I want something like this:
:
echo str_replace(
'<a href=',
'<a rel="nofollow" href=',
$part_cur_auth_obj->description
); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "author, nofollow"
} |
Woocommerce product permalink not working
I have added the product permalink in `Settings ->Permalinks` to Custom Base `/shop/%product_cat%` it works fine. But if I updated it to `/%product_cat%` products page working fine but website pages and posts are redirecting to 404 page. Any idea? | Well, WooCommerce documentation clearly states
> Please note: The product custom base should not conflict with the taxonomy permalink bases. If you set the product base to ‘shop’ for example, you should not set the product category base to ‘shop’ too as this will not be unique and will conflict. WordPress requires something unique so it can distinguish categories from products.
<
I think this may be a generic WP level rewrite issue: how do you match things across entity types (posts and taxonomies). There are big discussions on uh... rewriting the core rewrite systems because it has become a bottleneck < but it's probably a long-winded project. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "customization, permalinks, woocommerce offtopic"
} |
Wrap div-tag around posts in page
I'm creating a new Theme from scratch and I'm currently stuck with my post-page. I want a div-tag around every single post in that page. But I can't find the code that helps me with that.
What is curretly the case:
<div id="container">
<h2></h2> <!-- Start post-1 -->
<p></p>
<p></p> <!-- End post-1 -->
<h2></h2> <!-- Start post-2 -->
<p></p>
<p></p> <!-- End post-2 -->
</div>
What I want:
<div id="container">
<div id="post"> <!-- Start post-1 -->
<h2></h2>
<p></p>
<p></p>
</div> <!-- End post-1 -->
<div id="post> <!-- Start post-2 -->
<h2></h2>
<p></p>
<p></p>
</div> <!-- End post-2 -->
</div>
Thank you in advance. | What happen if you proceed with the following syntax?
<div id="container">
<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2 class="entry-title"><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
</article > <!-- /#post-<?php the_post_ID(); ?> -->
<?php endwhile; endif; ?>
</div> <!-- /#container -->
The additional things added:
* `post_class()`
* HTML5 semantic tag `<article>`, and
* The Loop
And:
> **Never** ever repeat same ID on a single view | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "posts, pages, single"
} |
How to display woocommerce products of one wordpress account in another wordpress account?
I have my main domain website with woocommerce products in one wordpress account(lets say WPAcc1) and my sub-domain(which is a blog) in another wordpress account(WPAcc2).
However, to access the woocommerce products that are present in WPAcc1 in WPAcc2, I'm just replicating the product here in WPAcc2 as well.
I've tried accessing the product through Woocommerce API. But, failed to retrieve the details. Is there any better way for that? or Can someone provide me insight on how can I use Woocommerce API to retrieve products from WPAcc1 to WPAcc2 in json format? | There's two ways. Firstly you can use XML feed from WP-Site1 on WP-Site2. thought this is a simple method and there's a builtin plugins out there in WP Plugin Directory. but if you are looking for more advanced and robust way (like data in json ) you can play with woocommerce REST API. here are some helpful links to get started with RESTful API in woocommerce. Woocommerce REST API Documentation & WC REST API | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "woocommerce offtopic"
} |
IMG size is set to width="964px" or "100%", but is shown as "634px" in browser
I have set up a theme with a width of 964 px, so that images in the post should be shown as 964 px, when set to 100% (or 964 px). I mean the complete width of the page/wrapper.
Unfortunately, this does not work, but I can not find the culprit.
Link: <
Code, I used:
html:
<img src=".../x.jpg" alt="" width="964px" class="alignnone size-full wp-image-150" />
css:
#posts {width: 964px !important;}
.post .post-excerpt img {max-width: 100% or 964px;}
Thank you, guys. | I found the problem. The content width was forced in functions.php:
...
if ( ! isset( $content_width ) ) $content_width = 634;
add_theme_support( 'automatic-feed-links' );
...
I changed the value to 964 and it works like it should. :) | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "images"
} |
Wordpress "HTTP error." when uploading Media - IIS
I am receiving the error message:
"HTTP error."
in Wordpress when trying to upload a 300 MB FLV file to the media library.
**Environment**
* Wordpress 4.7.2
* PHP 5.6.27
* IIS 7
* Windows Server 2008 R2 | The most common answer to this question is:
Check your php.ini settings and make sure the following variables are larger than the size of the file you're trying to upload (in this example we'll set the values to 500 MB):
upload_max_filesize = 500M
post_max_size = 500M
**However, in my scenario this was not the solution.** Instead we needed to do the following:
1. Launch Internet Information Services (IIS) Manager
2. Select the IIS server object in the Connections list on the left.
3. Double-click: Request Filtering
4. Edit Feature Settings...
5. Verify "Maximum allowed content length" is set to a value larger than your file size. The maximum value for this setting is 4294967295.
You may have site specific settings that override the global settings. If this is the case, step 2 is:
2. Select your site object in the Connections list on the left. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "uploads"
} |
Storing an array of objects related to each user
I need to store a potentially large array of stdClass objects (houndreds of items) on my various users. Is it safe to use user meta for this, or should I rely on something else?
I could store each object as a post, I guess, but that seems overkill as I'll almost always need to use the entire list at the same time.
The list of objects are unique for each user, so they can't be shared. | If the stdClass objects are all identical in structure, I suggest to create a specific table for them and use a reference to connect to the related user.
You can use a serialized user meta to connect a user to more than one record on that table, or use a specific table's column as "user_id" if one-object <=> one-user. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "wp query, database, users"
} |
wp core update not working anymore
I have a strange issue. Trying to update core wp version from 4.7 to 4.7.2 but wp keeps saying I am already up to date. But when I run
wp core version
Then I see 4.7 and not 4.7.2
Any ideas on how to troubleshoot ? | What is inside your `version.php` file?
File: /wp-includes/version.php
1: <?php
2: /**
3: * The WordPress version string
4: *
5: * @global string $wp_version
6: */
7: $wp_version = '4.7.1';
You can play with that number and test.
* * *
You can try to install the latest version of WP Cli and test. You may update to WP-CLI version: 1.1.0 if the older version had problems. (I found out you used the 1.0 version of WP-CLI before). | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "updates, wp cli"
} |
How to setup Landing HTML5 page in WordPress site
I have setup WordPress-oriented hosting on HostGator and I will be building a WordPress Site soon. At this point, it is a generic 'Hello World' default page. In the meantime, I found a fantastic HTML5 template for "Coming Soon" landing page.
What would be the most reasonable way to setup the "Coming Soon" HTML5 landing page? Does it make sense to try to place it 'within' WordPress or maybe remove the WordPress completely and have the HTML5 only, until the WordPress is built? | So yes, if you want to _only_ show the "Coming soon" page, _and_ keep working on your WordPress site at the same time, the best option is to move your WordPress installation somewhere else and only leave the HTML5 page.
Another option would be through plugins - there are plugins that exist to force all URLs on your site to go back to this special page, unless you are logged in. But you'd have to make sure the plugin in question allows you to modify the html of the default page it shows.
Any other solution that I can think of is going to be incomplete (i.e. people could still go look at mysite.com/wp-admin or any other URL they can figure out by themselves) and would prevent you from working on all or part of your site.
Hope this helps! | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "html5"
} |
How to access page variable inside action hook
I have an action hook which simply displays a contact form for signup:
add_action('woocommerce_single_product_summary','add_product_signup', 10, 2);
function add_product_signup() {
do_shortcode('[contact-form-7 id="20709" title="Product Sale Notification Signup"]');
}
This works ok BUT... I want to only show the form if the product is NOT on sale.
How can I access the 'on_sale' variable to test for true/false to then show/hide this contact form? | There is method on product class that is called `is_on_sale()` which actually determines if the product is on sale or not. You can access it from `global $product` variable. And must `echo` the `do_shortcode`. So the whole code will be like-
add_action('woocommerce_single_product_summary','add_product_signup', 10, 2);
function add_product_signup() {
global $product;
if( $product->is_on_sale() ) {
echo do_shortcode('[contact-form-7 id="20709" title="Product Sale Notification Signup"]');
}
}
> **The above code is tested. I tested it personally and it worked pretty well.** | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "filters, hooks, woocommerce offtopic, actions"
} |
Undefined index - get_option
I want to unset the css file if the checkbox is checked. This is working but the code give: " **Undefined index: simple_news_checkbox_css** "
$options = get_option( 'simple_news_settings' );
if ( 1 == ! $options['simple_news_checkbox_css'] ) {
add_action('wp_enqueue_scripts', 'hjemmesider_news_register_plugin_styles');
function hjemmesider_news_register_plugin_styles() {
wp_register_style('news', plugins_url('simple-news/css/news.css'));
wp_enqueue_style('news');
}
} | By default `get_option` gets you the value of your option.
I don't know anything about the specific option or the way it's configured. But basic knowledge of PHP suggests to me that the option `simple_news_settings` doesn't have an array key of `simple_news_checkbox_css` in some cases. So PHP is telling you the array doesn't have the key (or index, as that's the language of the error). An `isset($options['simple_news_checkbox_css'])` check before you try to access the value would stop PHP from complaining. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins"
} |
Extra Theme - Fit image inside of Featured Post Slider
I'm building a website with Extra Theme and I'm having one problem. The Featured Posts Slider isn't fitting my images. I already search and try a lot of things but none of them work. Thank you very much! | I solved the problem in the easiest way. I installed the Revolution Slider, and I used the Code Module with the Revolution Slider short code. Thank you for all the answers!! | stackexchange-wordpress | {
"answer_score": -1,
"question_score": 0,
"tags": "posts, themes, images, slideshow"
} |
How correct list-style displayed in firefox?
although the list-style for content is set to 'disk' in child-themes style.css, it is displayed as 'decimal'. In chrome-browser it is OK.
Is there any workaround to fix that? | Replace `"disk"` with `"disc"`
Here is some background: It has been reported, and they don't want to fix it:
<
based on a misinterpretation of:
<
Source | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "list"
} |
Add data-track to links in menu
Can anybody tell me how I can add a "data-track" tag to the links in my menu. When I go to the dashboard -> menus, I can add any custom HTML.
I would like it to go from this:
<a href=" index</a>
to this:
<a data-track="navigation|click|article-index" href=" index</a>
The first part of the code can always be the same (i.e. "data-track="navigation|click") the part at the end should copy the text from the link. In the example above that is "article-index", but it should just take whatever the text for the link is. (not sure if spaces are allowed....)
I haven't been able to do it myself, and I don't want to edit the core wordpress files. | So there's actually a filter for this, provided your theme doesn't use its own menu walker class:
function add_data_track_attribute( $atts, $item, $args ) {
$title = apply_filters( 'the_title', $item->title, $item->ID );
// $title = sanitize_title($title); // if you need a slug-like title
$atts['data-track'] = 'navigation|click|'.$title;
return $atts;
}
add_filter('nav_menu_link_attributes', 'add_data_track_attribute', 10, 3);
Note the commented-out line: I'm not sure what the data-track attribute does and, as you say, it might not allow spaces. If it doesn't, that line will transform the title into a slug, which should be acceptable for this.
Hope this helps! | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "menus, navigation"
} |
Why there is a 302 status when my account and password are right?
I captured all the http requests and responses when to login my wordpress with account and password.
Package number 22 is my http request when to login with account and password.
Package number 26 is my http response when to login with account and password.
Why there is a response ,package number 22,the status is 302? | Packet number 22 is not a request, but an aswer to a request. Status 302 just means the requested resource has been found and normally you are temporarily being redirected somewhere else. It doesn't say password is wrong or something liie that. Even on a successful login you are normally being redirected to the page you originally requested. In your case I guess the Response with 302 status code also redirects you to the page /wp/admin/. Thats why that page gets requested immediately after. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "login"
} |
Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?
I am a real fan of the **Allman (BSD)** coding indent style. However, when i review the top rated plugins on WordPress, i am finding them using the **K &R** coding indent style.
Is there a requirement from WordPress.org that forces users to use the **K &R** indent style when developing plugins or themes? I read all the manual but couldn't get a clear answer on which indent style we are allowed to use.
Your help will be greatly appreciated. | WordPress.org does not have any hard requirements for code styles for plugins or themes.
In the plugin guidelines, the relevant section is #4, "Keep your code (mostly) human readable." Mainly it is about obfuscation. The most relevant line is this:
> We recommend following WordPress Core Coding Standards.
Note the word _recommend_ , there. This is not a hard requirement.
The relevant portion of the theme review guidelines doesn't really mention code style directly, so there's no requirements for this kind of thing for themes either.
I'm kind of glad that there is some freedom here, but you will find that there's plenty of very messy code in the plugin directory, that doesn't really follow any one code style consistently at all. That's allowed—for better or worse. :-) | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "plugin development, theme development, customization, codex, coding standards"
} |
Add user meta after a user has registered and logged In
I have a very simple question . I am building a wordpress site where a after a user is created and logged in , there will be a link where he can click and add more information about him / her (let's say add Business info ) .
I don't want to spend time in doing this as i believe there are enough plugins that can achieve this . i tried wordpress user-meta , but unfortunately it only supports adding user meta during registration . | You can add user meta after login by using the `wp_login` hook. Make sure to set a higher priority (99 - the default is 10) to make sure to get the data after everything has processed in the core `wp_signon()` function.
From the Codex ...
function add_my_user_meta_after_login( $user_login, $user ) {
//Add my user meta code
}
add_action('wp_login', 'add_my_user_meta_after_login', 99, 2); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "plugins, wp query, theme development, user meta, profiles"
} |
to create a custom post type with additionnal url field such as link to social network and an email field
I'm a low beginner with wordpress and I have to create a custom post type with additionnal custom fields: link for social network and a field for email address.
the purpose is to have a page with the members of a team and for adding a new member we need to allow him or her to add his or her name, an email address and a her or his profil link for a social network without using a plugin like ACF.
Need some help :-) Thanks | Custom Post types allow to set custom fields (aka meta-data) capability. Just add `'custom-fields'` capability to your arguments within the array. No need for the plugin just for adding a couple of fields.
'supports' => array( 'title', 'editor', 'custom-fields' ) | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "custom field"
} |
Is there a way to schedule automatic WordPress core updates?
Is it possible to take advantage of automatic WordPress core updates but schedule when they occur? I would like to avoid updates happening, say, at 11pm on a Friday, in the event that they cause issues with the site that would require maintenance or intervention. | Core updates (as other things that happen without explicit action by admin) _are_ scheduled. However WP scheduling system (WP Cron) act on _intervals_ (every N seconds) and has certain amount of drift on top since it it triggered by visits to the site.
In a nutshell it's not too favorable to implement more elaborate date/time rulesets into it firing.
You could reverse the logic by _preventing_ core updates within certain times, but really I would recommend to stick with security-only auto updates or manual updates altogether if your site is sensitive enough to it. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "updates, core"
} |
On local machine can't log in or reset password but I can log in on the live version, user has activation key in database
I'm working on a local copy of a site that is online and I can't log in or reset password for my user and I can't figure out why. I can click to reset the password with the "forgot password" button and it says to check my email but nothing ever shows up. So I checked the database and it says the user has an activation code but no email ever showed up. Any idea what is going on? Is | Your local server probably has problems sending mail. There are ways to fix that, but it is probably easiest to change the password in the database directly. Since you've made a copy of your site I am going to assume you have access to the database through something like PhpMyAdmin. Follow these instructions to change the password: < Short version: find your user in the wp_users table, type a new password in the user_pass column and make sure to select MD5 under functions.
To prevent this problem in the future you could install a SMTP mail plugin. There are quite a few in the plugin directory for this.
Good luck! | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "activation, password, email verification"
} |
Is it possible for a plugin to force reading and writing of uploaded images to a database instead of to a filesystem?
I am trying to configure a WordPress site using a server cluster and independent file systems. The problem is keeping the wp_content/uploads folder synchronized across all the server instances. My preferred solution is to "write" and "read" these files to/from a shared database.
So my basic question is whether this is possible to code in a plugin, or would require WordPress core modifications (which I'd rather avoid). | Yes, you should have quite reasonable options to customize upload, there are plenty of existing solutions around.
As for specifics I am not sure on "database" as image storage option. They typical solutions that I've heard of are:
* dedicated location behind CDN (or some variation of);
* dedicated image storage service, such as Amazon S3. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "plugins, plugin development, core, uploads"
} |
How do I get a certain set of posts from the database?
We've just finished redesigning a blog that has almost daily posts.
Over the past month that we were redesigning it, there have been a large number of new posts that now need to be reincorporated into the database before we deploy the new site.
To get these new posts and upload them into the new site's database, what is the procedure? My guess is that we need to:
1. Export a sub-section of wp_posts and then import that into the new site.
2. Download recent content from wp-uploads and upload that into the same directory in the new site.
So when I'm exporting that most recent sub-section of wp-posts, what is the procedure to follow? And how do I coordinate that with the corresponding records in the wp_postmeta table?
Are there any other tables that need to be exported as well?
Thank you. | Login to your admin and go to "Tools -> Export" and you can customise what you want to export. Use the "Tools -> Import" on your other site.
If you have missing images, just copy them over from your `/uploads/` directory over to the new site | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "posts, database"
} |
vertical menu bar
I am trying to generate a menu using wp_nav_menu.I am stuck this . My expected output is this: Go!
<a href="index.html" class="list-group-item">
Home
</a>
<a href="about.html" class="list-group-item">About us</a>
<a href="service.html" class="list-group-item">Services</a>
<a href="allumi.html" class="list-group-item">Allumi</a>
</div>
And i am using this code to aquire this:
'Primary Menu', 'menu_class' => 'list-group-item','items_wrap'=>'%3$s' ]); ?>
i am not getting the expected result.can anyone help me? | You can either use a filter in your functions.php file:
function mytheme_nav_menu_css_class($classes, $item, $args) {
if($args->theme_location == 'secondary') {
$classes[] = 'your-class-name';
}
return $classes;
}
add_filter('nav_menu_css_class','mytheme_nav_menu_css_class');
Or if you go to your WP Admin, click Appearance -> Menus and then click the tab at the top "Screen Options", you can tick `CSS Classes` which will enable you to add a class to each list item in your menu.
See this article for details. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "menus"
} |
Wordpress on AWS with ELB
The plan is to install wordpress on AWS with ELB. So far I have two instances of Ubuntu 16.04 each with PHP7 and both connected to RDS (MariaDB).
The PHP Session is shared between the ec2 instances and hosted in ElastiCache (Memcached). So in php.ini, at the session section, I use memcached. If I have only one ec2 under the ELB, I can login to the admin and all is perfect.
The problem is when have both of them under ELB (the exact same config) the website is working but the login in the admin no any more. Does someone have any idea/clue/suggestion about this matter? Thank you | Finally I managed to solve this issue. The problem i had was on the ELB with the sticky sessions. I just enabled it and set a time of 3600 and now wordpress in login in users. A question remains with the real ELB power. If you do this sticky session I found some documentation that says the user is bind to one single EC2 exclusively .. feel free to comment over this. Thanks again | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "plugins, php, multisite, wp admin"
} |
What is the difference between current_page_parent and current_page_ancestor?
In the function `wp_page_menu` there is an auto-generated `classes` to the list elements and the function generates `current_page_parent` and `current_page_ancestor` to a parent menu item if I clicked a child menu item (I mean if the current page is the child menu element). So now why does WordPress generate two different classes for the same element.
` and it's not working on my nginx server so I decided to test this.
I created a file called `test.php` and inserted:
<?php $response = wp_remote_get( ' );
print $response ['body']; ?>
When I run this file I am getting error:
2017/02/04 16:22:31 [error] 16573#16573: *461100 FastCGI sent in stderr:
…
"PHP message: PHP Fatal error: Uncaught Error: Call to undefined function
wp_remote_get() in /var/www/html/wp-content/themes/x-child/test.php:1
I cannot tell why this would be undefined function, given that its part of wordpress core? | The very concept of HTTP API is to make sure transport will be done. It basically uses 5 different transport methods and it chooses the best one according to your server config. So it's unlikely a compatibility issue with `wp_remote_get()` and your server.
Plus if WP is not loaded, adding an action won't help, it will fail the same with undefined function error but this time on `add_action`.
So basically you're missing WordPress, for test purpose you could do this (assuming your file is at the root of WP installation ) :
<?php
require_once( 'wp-load.php' );
$response = wp_remote_get( ' );
print $response ['body']; ?> | stackexchange-wordpress | {
"answer_score": 5,
"question_score": 1,
"tags": "functions, core, wp remote get"
} |
Why I can't add a script-code into theme-settings without 403-forbidden?
we (my son and me) modified a script - '/js/sticky-menu.js' - and it only works when Cloudflare 'Rocket Loader' is off.
Following the tutorial for Rocket Loader I tried to exclude the script by adding this code into the header (using theme settings of Genesis):
<script data-cfasync="false" src="/javascript.js"></script>
I modified the code to
<script data-cfasync="false" src="/js/sticky-menu.js"></script>
After saving the code I got this warning-message:
> 403 Forbidden
>
> A potentially unsafe operation has been detected in your request to this site.
Also using the complete path of the script doesn't work.
Here is the URL of my website.
Have you a solution for this problem?
kind regards, Rainer Brumshagen | # Solution:
Because the theme JavaScript is not in:
/js/sticky-menu.js
Rather, it's in your theme folder (as your theme name is `lifestyle-pro`, as found from your site's HTML):
/wp-content/themes/lifestyle-pro/js/sticky-menu.js
So your `<script>` CODE should be:
<script data-cfasync="false" src="/wp-content/themes/lifestyle-pro/js/sticky-menu.js"></script>
# Bonus:
This can be made better with the use of the WordPress function `get_stylesheet_directory_uri()`. In that case, your CODE will be:
<script data-cfasync="false" src="<?php echo get_stylesheet_directory_uri(); ?>/js/sticky-menu.js"></script>
An even better method is to use `wp_enqueue_script()` function in combination with `wp_enqueue_scripts` filter hook, as described in this WordPress document. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "headers"
} |
What is the recommend directory in which I can upload a new library?
I am trying to install prebid.js to wordpress and I am still new to the whole structure of the wordpress installation. Is there any directory that I can safely upload to without breaking any dependencies or worrying about it being delete with an update? | You can create a child theme folder named `yourTheme-child` in your theme's folder, and then upload your JavaScript files in that folder. (notice that `yourTheme` is the name of your theme's folder)
You might also want to create a folder named `js` inside that.
Take a look at : Child Themes
Child themes will not be deleted after updating your template/wordpress.
Then you can simply include your Js file in the header/footer this way:
`<script type="text/javascript" src="Full URL Goes Here"></script>`
or even better, enqueue your script it in the **functions.php** file using the below code:
function my_custom_script() {
wp_enqueue_script( 'my-custom-js', 'Full URL Goes Here', false );
}
add_action( 'wp_enqueue_scripts', 'my_custom_script' ); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 2,
"tags": "directory"
} |
featured image different style on the list and on single post
please take a look at my test site -> <
I managed to change a featured image style on the list of posts but then it is also changed when you click the full post. What I want to get is small thumbnail in the list of posts as it is now, and larger image in full post. Is it possible? Like two classes/containers for list and single post view? If it is possible I would like also to change a title style for list and single post.
Something like it is here: < | I saw you installed twentytwelve theme, So follow there steps
Open file content.php in root folder theme and find
the_post_thumbnail();
change to
if ( is_single() ) :
the_post_thumbnail( 'full' );
else :
the_post_thumbnail( 'thumbnail' );
endif; | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "post thumbnails"
} |
How to fully backup a WordPress site?
I want to take a full backup of a WordPress website regularly (manual or automatic), including files, database, etc. how to achieve this? | To backup WordPress website (on your own host), you have 2 options.
**Option 1**
Use a plugin such as BackUpWordPress.
**Option 2**
Backup database and your contents individually.
* To backup your database, you will have to sign in to your cPanel/DirectAdmin area and head over to database section of the panel. There, you can select your database and make a backup of it, saving it on a safe place for further use.
* To backup your content, head over the the file manager section of your cPanel/DirectAdmin area, select and backup the `wp-content` folder. You can also download it and save it.
Remember, you will also need to have a backup of your `wp-config.php` file, existing in the WordPress's root folder. If you want it to be more safe, you can backup the entire WordPress's folder. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "backup"
} |
What is the best practice for making a WP plugin that I want to develop responsive?
What is the best practice for making a WP plugin that I want to develop responsive, meaning compatible for all devices?
When writing WP plugin, can you use frameworks like Bootstrap? | Its totally up to you. you can use `Bootstrap` or any other UI Framework for styling your plugin. WordPress don't restrict you from using such frameworks but you should keep WP coding standards in mind. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins, design"
} |
If tag x then show y + tag name(s)
I would like to have on my `single.php`:
_Tag: Tag1_
Or if more than one Tag:
_Tags: Tag1, Tag2_
The `Tag1` and `Tag2` should link to a custom URL.
I found this, but don't know how to get exactly what I want.
if( has_tag() ) {
// somehow echo "Tags" + Tagnames with custom links seperated by commas.
}
else{
// show nothing
} | you can use the `get_the_tags` function, something along the lines of:
$posttags = get_the_tags();
if ($posttags) {
echo (count($posttags) > 1) ? 'Tags: ' : 'Tag: ';
$links = array();
foreach($posttags as $tag) {
$links[] = sprintf('<a href="%s">%s</a>', get_tag_link($tag->term_id), $tag->name);
}
echo implode(', ', $links);
}
Reference: < | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "tags"
} |
WP_Query date_query - Use unix timestamp?
I am trying to perform a WP_Query, passing the values for `before` and `after` in the `date_query` as unix timestamps.
This does not seem to work:
$args = array(
'date_query' => array(
'before' => 1486045020
)
);
I know I could use php's `date()` function to format it to a year, month and day, but I would rather use a unix timestamp to avoid time difference issues. | I found the solution - I used PHP's `date()` function to format it into a ISO 8601 compliant format, so there is no confusion around timezones, etc.
$args = array(
'date_query' => array(
'before' => date( 'c' , 1486045020 )
)
); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "wp query, date query"
} |
How are WordPress Page URLs affected by permalink settings?
I am finding tons of tutorials about the why and how of modifying permalink structure for _posts_ , but absolutely nothing about pages.
Right now, my permalink settings are "plain", which uses a query string for everything. This means all pages are `/?page_id=12345`, for example. I have pages organized into a hierarchy, and have slugs defined for all of them; so I obviously want my page URLs to be `/parent_slug/page_slug`.
How are page permalinks affected by WordPress's permalink settings? All of the examples are for posts, and involve posting date and category; neither of which are applicable to pages. | Pages aren't affected by permalink settings beyond "Pretty Permalinks" being either on or off. Any format other than _Plain_ will enable page slug permalinks, as long as your server is set up to support it. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "permalinks, pages, url rewriting"
} |
Wordpress database error with latest WP - "WP_termmeta doesn't exist"
I've just upgraded to 4.7.2, and now I see this message:
WordPress database error: [Table 'myusername.wp_termmeta' doesn't exist]
SELECT term_id, meta_key, meta_value FROM wp_termmeta WHERE term_id IN
(2,3,4,5,6,7,8,9,10,11,12,13,1,14,15) ORDER BY meta_id ASC
What's the correct solution to this issue? I upgraded the database while upgrading. Lots of googling suggests strange things like upgrading to some beta releases, which I cannot do in production -- that might be worse.
Welcome any pointers! | You are missing a table. You can add it using this sql
CREATE TABLE `wp_termmeta` (
`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`term_id` bigint(20) unsigned NOT NULL DEFAULT '0',
`meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`meta_value` longtext COLLATE utf8mb4_unicode_ci,
PRIMARY KEY (`meta_id`),
KEY `term_id` (`term_id`),
KEY `meta_key` (`meta_key`(191))
) ENGINE=InnoDB AUTO_INCREMENT=3255 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; | stackexchange-wordpress | {
"answer_score": 13,
"question_score": 6,
"tags": "database, fatal error"
} |
How to add some php code in header.php using plugin
is there any way to add some php code on top in header.php file, i want to add ob_start(); function in my theme header.php file using plugin.
i used the following code but it not working
add_action( 'wp_head', function(){
echo "<?php ob_start(); ?>"
} | Looks like just syntax:
add_action( 'wp_head', function(){
ob_start();
} | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "themes, theme options, headers"
} |
body class according to number of published custom posts
Is it possible to add a number to the body class according to how many custom posts a current user has published, e.g. CUSTOMPOST-4 | add to functions.php
function wpc_body_class_section($classes) {
if (is_user_logged_in()) {
$classes[] = 'CUSTOMPOST-'.count_user_posts(get_current_user_id());
}
return $classes;
}
add_filter('body_class','wpc_body_class_section'); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -2,
"tags": "custom post types, body class"
} |
How to add a post option in wordpress like facebook
I need a post feature like facebook post option (ie., when a url is copied from external and paste in facebook post, it retrieve image and few content to show) like this I need to do in wordpress, any suggestions | you can search for **Link preview WordPress Plugin**
There are several WordPress Plugins to do that, you can find here :
< | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -3,
"tags": "posts, facebook"
} |
is it possible different visitors location to show different informations?
I am making a site but i am searching for plugin but I cant find any,
What i want to do is, I have a "Contact page" with informations
USA Street phone etc. and AUS Street phone etc. but what I want to do is, If the visitor is from USA i want to show only the US informations and if the visitor is from AUS i want to show only the Aus informations.
Is there any plugins that i can use or i need to do it somehow manually? | I have found solution what I am looking for,
This is the plugin that i will use if anyone interested
< | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins"
} |
Child theme function.php causes fatal error
When I copy an exact copy of the function.php file to the child theme folder I get this error.
Fatal error: Cannot redeclare archi_theme_setup() (previously declared in /home/desi3442/public_html/wp-content/themes/archi-child/functions.php:28) in /home/desi3442/public_html/wp-content/themes/archi/functions.php on line 71
I dont quite understand the error cause its pulling function.php from the main theme files when the child functions.php is supposed to overwrite it correct? | This is because the same function exists in the parent.
archi_theme_setup()
Since you are under the same namespace there will be a name collision -- PHP cannot hold two functions with the same name.
 {
if( get_post_type() == 'attachment'){
$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,ul,ol,li,code,close' );
$settings = array(
'wpautop' => true,
'textarea_name' => 'content',
'textarea_rows' => 10,
'media_buttons' => false,
'tinymce' => true,
'quicktags' => $quicktags_settings,
);
return $settings;
}
}
add_filter( 'wp_editor_settings', 'add_editor_support_for_attachments' ); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "images, media, tinymce, visual editor, description"
} |
Internationalization of strings with html tags and numbers in WordPress
How to translate a string with tags in between.
Suppose there is a string like
$a = 5;
There are <?php echo $a; ?> <span>people</span> in this country.
Javascript files:
wp_localize_script( 'store-locator', 'storelocatorjstext', array(
'nostores' => __( 'There are 5 people in this country.', 'textdomain' )
) );
What is the correct way of internationalizing such cases?
My approach:
<?php _e('There are 5 <span>people</span> in this country.', 'textdomain'); ?> | You can wrap the translation in a printf function. printf ( or sprintf for when you don't want to print to the screen immediately ) allow you to put placeholders in the string. See the documentation for all the type specifiers
Use __() instead of _e() because printf already outputs to the screen.
$no_people = 5;
printf( __( 'There are %d <span>people</span> in this country.', 'textdomain' ), $no_people );
* * *
**Edit**
Added example for wp_localize_script
$no_people = 5;
$nostores = sprintf( __( 'There are %d <span>people</span> in this country.', 'textdomain' ), $no_people );
wp_localize_script( 'store-locator', 'storelocatorjstext', array(
'nostores' => $nostores
) ); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "localization"
} |
WordPress Theme redirects to the Index page - Theme customizer problem
I bought this WP Theme: WP Theme
I installed it on my webspace, everything worked.
Now I would like to customize it, but everytime I click on the customizer the theme redirects me back to the index page, is this a general issue or does this happens only on this theme? | Roman, opening the theme customizer should open the special theme customize option not to redirect to the index page.
You can check if this is theme problem if you set default WordPress theme for a moment and open the customizer from there. That theme should work well with the customizer.
If this is so, then you need to contact the theme support.
Else you have some configuration problems of another kind. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "themes, theme customizer"
} |
opening links in new tab using - add_filter( 'the_content', 'make_clickable');
The following code in function.php, works fine for making the links - clickable,
add_filter( 'the_content', 'make_clickable', 12 );
But can I make the links to open in new tab? | I am not sure if there's a native function for this, but a little regex might help the case:
function open_links_in_new_tab($content){
$pattern = '/<a(.*?)?href=[\'"]?[\'"]?(.*?)?>/i';
$content = preg_replace_callback($pattern, function($m){
$tpl = array_shift($m);
$hrf = isset($m[1]) ? $m[1] : null;
if ( preg_match('/target=[\'"]?(.*?)[\'"]?/i', $tpl) ) {
return $tpl;
}
if ( trim($hrf) && 0 === strpos($hrf, '#') ) {
return $tpl; // anchor links
}
return preg_replace_callback('/href=/i', function($m2){
return sprintf('target="_blank" %s', array_shift($m2));
}, $tpl);
}, $content);
return $content;
}
add_filter('the_content', 'open_links_in_new_tab', 999);
The patterns might need a little improvements. Hope that helps! | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 4,
"tags": "functions, customization, filters, links"
} |
Creating new content types (Pages, posts, testimonials, tigers, oh my!)
I have a blog on my WordPress site but I have a different type of content that I want to organize in a similar way: a collection of curated media content for language learners. The blog structure's tag feature would be very helpful.
I see that there are multiple content types. How does one create their own? | You'll need to add a Custom Post Type | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "templates"
} |
Changing the default wp_search_stopwords
I want to change the default stopwords in the wordpress search. I'm sure it's easy but I can't figure it out.
Per this < the default stopwords are:
$words = explode( ',', _x( 'about,an,are,as,at,be,by,com,for,from,how,in,is,it,of,on,or,that,the,this,to,was,what,when,where,who,will,with,www',
'Comma-separated list of search stopwords in your language' ) );
So, I would think I could just add_filter it in like this:
add_filter( 'wp_search_stopwords', array('meh') );
But `meh` is still being applied to the search results.
I found this < which has the following at the end, but I don't know what to do in the `do whatever you want` part:
function a_whatever() {
remove_filter( 'wp_search_stopwords', __FUNCTION__ );
// do whatever you want
}
add_filter( 'wp_search_stopwords', 'a_whatever' );
Thanks! | You are close: you indeed need to define a filter, but you've not quite gotten the filter definition right:
function add_meh_stopword($stopwords) {
$stopwords[] = 'meh'; // *add* "meh" to the list of stopwords
// if instead you want to completely replace the list of stopwords
// use $stopwords = array('meh');
return $stopwords;
}
add_filter( 'wp_search_stopwords', 'add_meh_stopword');
The second argument to the `add_filter` function takes a "callable", i.e. in this case a function name. That function then returns the modified list of stopwords.
Hope this helps! | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "wp query, filters"
} |
Empty search results return soft 404
I have recently been notified by Google Webmaster tools that there has been an increase in soft 404 pages. This is due to no results being returned by pre-defined links to search queries that are intended to filter through custom post types that have predefined tags.
What would be the best way to prevent a 'soft 404', and satisfy Googles detection settings? | Use a web service such as W3C Link Checker to find out the broken links and fix it. Also based on what you described, if it a self-developed theme and caused due to search, make sure you will have a content template that handle the `none` content situation. You can check your theme's `search.php` and see how it handles the `none` content situation. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "search, 404 error"
} |
How to resize video lightbox popup in wordpress?
I am using videolightbox in WordPress.
Video Popup size is too big see here almost covering the whole page.
I want to change the pop-up size to a smaller one, at the same time I would like to keep the responsiveness of the page.
Can you please help? | Check the avada-documentation:
-> Menu -> Extra -> Videos In Lightbox -> How To Set Video Size in Fusion Theme Options
**How To Set Video Size in Fusion Theme Options**
Step 1 – Navigate to the Avada > Theme Options tab.
Step 2 – Go to the Lightbox tab, and locate the Slideshow Video Width and Height options. Set the width and height of your video by entering a pixel value into the corresponding setting. For example,1280px for the width and 720px for the height. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "theme development, css, responsive, lightbox"
} |
WP Rest API v2.0 user profile update issue
I'm using WP Rest API plugin to use Wordpress as backend of iOS app. I need to update the username using the following endpoint
And this is the response I got.
{
"code": "rest_cannot_edit",
"message": "Sorry, you are not allowed to edit resource.",
"data": {
"status": 401
}
}
It seems that the Rest API plugin does not support user profile update, or am I missing some authentication parameters?
Thanks in advance, looking forward the best solution. | I found the answer from below.
<
Authentication is the primary step for all API works. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "plugins, json, rest api"
} |
How can I load a page template from a plugin?
I want to add page templates to a theme directly from the plugin. The idea is that the template would show up in the dropdown under Page Attributes, and all the code would need to be in the plugin.
Any tips on how to achieve that ? | You can use the `theme_page_templates` filter to add templates to the dropdown list of page templates like this:
function wpse255804_add_page_template ($templates) {
$templates['my-custom-template.php'] = 'My Template';
return $templates;
}
add_filter ('theme_page_templates', 'wpse255804_add_page_template');
Now WP will be searching for `my-custom-template.php` in the theme directory, so you will have to redirect that to your plugin directory by using the `page_template` filter like this:
function wpse255804_redirect_page_template ($template) {
if ('my-custom-template.php' == basename ($template))
$template = WP_PLUGIN_DIR . '/mypluginname/my-custom-template.php';
return $template;
}
add_filter ('page_template', 'wpse255804_redirect_page_template');
Read more about this here: Add custom template page programmatically | stackexchange-wordpress | {
"answer_score": 15,
"question_score": 12,
"tags": "plugin development, filters, templates, page template"
} |
Use WordPress search in external static website
I've created a static website for my main WordPress website.
I'm trying to add the WordPress search form in my static page so I can still use the search form from my static website.
Here's what I have now:
<form action=" method="get">
<input type="search" name="s" value="" placeholder="type keyword(s) here" />
<button type="submit" class="btn btn-primary">Search</button>
</form> | You would need to query the Wordpress site from your form using the REST API. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "search, twitter bootstrap"
} |
html generated by theme exist but doesnt appear in browser
I am using this plugin, and I put
> wp_head() and wp_footer() calls in my header.php and footer.php files respectively
just like the site said. I allowed in configurations to use shortcode (just like the site said) and also put the code
<?php echo do_shortcode('[responsive_menu]'); ?>
in my `page-however.php`, but when I refresh the browser, the menu is not appearing. When I inspect my site code, it appear just like this:
;
function WC_test_gateway_plugin{
class my_gateway extends WC_Payment_Gateways{
//code
}
}
?>
But when I put it into global scope, it will show that the WC_Payment_Gateways is undefined.
<?php
class my_gateway extends WC_Payment_Gateways{
//code
}
?>
What's the difference between these 2 practices?
Is it a bad practice to put class definition inside callback function? Any better way for it? | Use your class definition in a separate file, say in `/your-plugin-dir/classes/my-gateway.php` like usual:
<?php
class my_gateway extends WC_Payment_Gateways {
//code
}
?>
Then use this CODE to include the file on `plugins_loaded` action from your main plugin file:
add_action('plugins_loaded', 'WC_test_gateway_plugin');
function WC_test_gateway_plugin() {
require_once plugin_dir_path( __FILE__ ) . 'classes/my-gateway.php';
// instantiate your class here or in your class file or anywhere after this function is called.
}
Now you'll get access to `WC_Payment_Gateways` because by now `WC_Payment_Gateways` is defined, since WordPress fires `plugin_loaded` action hook only after all the plugins have loaded their main files. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "plugin development, woocommerce offtopic"
} |
Shortcode Function - Can't get anything else to return after running shortcode within shortcode
Just looking to see if anyone can help me with a problem I have when returning values within a shortcode.
function youtube_media_shortcode() {
return do_shortcode( '[x_video_embed no_container="true"]<iframe width="560" height="315" src="'.get_field('youtubeurl', 'option').'" frameborder="0" allowfullscreen></iframe>[/x_video_embed]' );
return '<div class="youtube-text">'.get_field('youtubetext', 'option').'</div>';
}
The first part of this returns fine with the video but then it does not seem to return the next line. If I remove the first line then the second one returns fine. I presume it has something to do with the do_shortcode but I have no idea what!
Any help is appreciated :) | You shouldn't call return twice in a function, as it isn't supported and only the first return is evaluated.
What you can do is assign the first do_shortcode to a variable and return the variable concatenanted to the second return.
function youtube_media_shortcode() {
$shortcode_output = do_shortcode( '[x_video_embed no_container="true"]<iframe width="560" height="315" src="'.get_field('youtubeurl', 'option').'" frameborder="0" allowfullscreen></iframe>[/x_video_embed]' );
return $shortcode_output . '<div class="youtube-text">'.get_field('youtubetext', 'option').'</div>';
} | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "functions, shortcode"
} |
function query_posts disabling current_page_menu class
I have a header and a footer menu (they're the same: Primary Menu). When I'm on a page, wordpress adds classes like `current_page_menu`. But on pages where I use the `query_posts()` function the menus **after** this function dont have those classes added like `current_page_menu` etc.
Here is my code that is causing the bug:
<?php
$title_slug = strtolower(str_replace( " ", "-" , the_title_attribute('echo=0') ) );
$id_obj = get_category_by_slug($title_slug);
$cat_id = $id_obj->term_id;
query_posts( 'cat='.$cat_id.'&post_status=publish,future&paged='.get_query_var('paged') );
?>
This code is very useful, though. As it ensures to create a category page by adding a page and selecting the category page template instead of just a link to that category. I had to do this because my category pages need to have child pages.
I'd be greatful if anyone knows a solution! | The issue is caused by the `query_posts` function, this function alters the global $wp_query which the menu walker uses to check and add classes like `current_page_menu` to menu items.
A solution would be to write a new custom query and loop through that than using `query_posts`.
$title_slug = strtolower(str_replace( " ", "-" , the_title_attribute('echo=0') ) );
$id_obj = get_category_by_slug($title_slug);
$cat_id = $id_obj->term_id;
$args = 'cat='.$cat_id.'&post_status=publish,future&paged='.get_query_var('paged');
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
//YOUR CONTENT
<?php endwhile; ?>
/* Restore original Post Data */
<?php wp_reset_postdata(); ?>
<?php endif; ?>
**References:**
* query_posts
* WP_Query | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "categories, menus, query, query posts"
} |
Export navigation menu
I want to export all navigation menu's from one site and import the menu's in another site. I have tried to export the tables:
* `wp_posts`
* `wp_postmeta`
* `wp_terms`
* `wp_termmeta`
* `wp_term_relationships`
And import them in another database. This does not seem to work. Can someone point me in the right direction? | WordPress has an Import/Export tool, but it doesn't works with nav menus only, the "All Content" option will export the menus too, but with everything else that is in your site (including posts/pages in the trash) you can try this plugin so the Menu option shows in the Export page. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 5,
"tags": "navigation, import, export"
} |
can't access my site
I was trying to link up my new domain to my wordpress site but it went horribly wrong.
Im hosting my site on a AWS EC2 instance, i changed the URL in the settings on my wp-admin.
I have tried adding the lines to wp-config.php but yet that didnt fix it. I have tried going into my wp_options in MyPHPAdmin and changed the URL's back but thats not worked either. I have also tried editing the functions.php file and thats not working either :/
Help? | Fixed it. Once i enabled debug I found out the problem was infact that the function.php was in wp-include aswell as wp-admin. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "site url"
} |
Position a hard-coded menu item
I used a piece of code I found here in wordpress.stackexchange to add a custom link to my menu/nav. I adapted to my needs and it works great. The problem is it adds the link in the first position in my navigation list but I want it at the end after the other links.
Does anyone know how to make that happen?
function new_nav_menu_items($items, $args) {
if( $args->theme_location == 'primary' ){
$homelink = '<li><a class="sites-button" data-toggle="animatedModal10">cool</a></li>';
$items = $homelink . $items;
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items', 1, 2 ); | Try changing this line:
$items = $homelink . $items;
to
$items = $items . $homelink; | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "customization, menus, navigation, links"
} |
wp_customize_support_script - do I need it?
I've noticed a random JavaScript function at the end of the source code of my WordPress website.
<script type="text/javascript">
(function() {
var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\\s+)(no-)?'+cs+'(\\s+|$)');
request = true;
b[c] = b[c].replace( rcs, ' ' );
// The customizer requires postMessage and CORS (if the site is cross domain)
b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs;
}());
</script>
A quick google search lead me to the article below, but I didn't find it very informative.
<
Does anyone know what _exactly_ this script does, and if it is required? | Yes, it is needed. For reference, the function's description is:
> Prints a script to check whether or not the Customizer is supported, and apply either the no-customize-support or customize-support class to the body.
The class names that the function toggles on the `body` element control whether or not the Customize link in the admin bar is displayed. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 3,
"tags": "javascript, theme customizer"
} |
Method to find a hook
Is there an effective method to find a place where wordpress's hook is declared and when it's activated?
For example:
I know that `get_header` hook is declared inside `wp-includes\general-template.php -- function get_header(...)`. When this function is called, the hook is activated.
In this case that was easy but the rest hooks are harder to localize e.g the hooks in admin dashboard. | Here in this page its the list of all action and filter hooks, just click on one and it will tell you in which file you can find it, a partial view of where is declared, and below are the related hooks.
you can see a list of hooks and the functions attached to it using:
$hook_name = 'wp_head';
global $wp_filter;
var_dump( $wp_filter[$hook_name] );
i am using 'wp_head' as an example, but you can use a hook related to the event (you said location) and start digging, for known events you can just do a google search, the common ones will show, and you can use them as `$hook_name` | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 1,
"tags": "hooks"
} |
How to remove /year/month from uploaded medias?
I have removed year/month from my media's structure, But still i have a thousand of images using the old structure.
I need to remove the year/month from these published attachments, however i noticed that the metadata saved in the database is serialized and i can't simply use a text editor to replace them.
There is a plugin called `Better search & replace` that considers serialized data while changing the database.
Is it enough to just replace the URLs from for example `2016/10/` to empty in order to remove it (in `wp_postmeta`)? or i have to do it in other tables too?
I copied all my images to a single folder and i'm sure i don't have duplicate filenames. | i checked the database and noticed that every date is stored in a format like `2016-07-11`. i did not found any date like `2016/07/11` but maybe some other plug-ins use it but none of my plug-ins use it
every date like `2016/07/11` was in the link so i think you can do it by search replace but be careful and have a backup of your database
also don't change guids they are needed for `rss reader` | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "permalinks, database, mysql"
} |
Grabbing a data from wp_usermeta
I installed a new plugin and it created some meta data for me in the `wp_usermeta` table
`meta_value a:1:{i:0;a:2:{s:7:"site_id";i:1;s:5:"posts";a:2:{i:0;i:4;i:1;i:178;}}}`
A few questions:
1. what kind of data format is this?
2. what is a:1 and a:2?
3. the values im trying to grab are 4 and 178. How would i go about pulling this information? | That is PHP serialized data. It is how PHP creates a storable version of data that retains its structure.
Don't try to work directly with data in the database, use API functions like `get_user_meta` and you don't have to worry about how it is stored. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "customization"
} |
How to fix ob_end_flush() error?
At the bottom of my WP-admin pages I get this:
ob_end_flush(): failed to send buffer of zlib output compression (1) in C:\Users\anticaking\Desktop\Website\wordpress\wp-includes\functions.php on line 3718.
Line 3718:
function wp_ob_end_flush_all() {
$levels = ob_get_level();
for ($i=0; $i<$levels; $i++)
ob_end_flush();
}
I've removed all plug-ins and swapped themes and still get the error so I cannot pinpoint what is causing it. What is it and how do I fix this? | I also had this issue with wordpress and couldn't properly resolve it. Ended up with this filthy hack to prevent the error from showing:
// Get the current error reporting level
$e_level = error_reporting();
// Turn off error reporting
error_reporting(0);
ob_start();
echo 'This is a horrible hack';
$buffer_contents = ob_get_clean();
ob_end_flush();
// Reset error reporting level to previous
error_reporting($e_level);
Everything does seem to work as expected, however I'm not proud of it! | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 3,
"tags": "errors"
} |
Compress WordPress core files ( JS and CSS )
I checked WordPress core files, and I found a lot of uncompressed JS and CSS files. Is there any disadvantage, if I compress these files using YUI-Compressor?
Secondary question: Why didn't compress these files
Thanks! | Minifying the CSS and JavaScript files is totally optional.
The most important result is that your files are going to take less space, and be served more quickly. This will result in saving bandwidth, if you have a limited plan. These files will be executed in the client, so the more optimized they are, the better user experience they create.
The core files are not compressed by default because developers may need to debug/modify the code, and it's pretty hard to debug a minified code, until you unminify it first.
However, sometimes compressing JS files may result in errors and jQuery conflicts. But if the plugin does it's job neat, then there shouldn't be a problem.
Automtimize is a well known plugin for minifying and combining scripts and styles without a problem. | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "compression"
} |
Custom excerpt legnths for specific pages
Hello I need help customizing the excerpt length for specific pages.
For the homepage excerpts I want 400 characters and for all other pages I want 800 characters.
I came up with the following code placed in functions.php
function wpdocs_custom_excerpt_length( $length ) {
if( is_front_page() ){
return 400;
} else {
return 800;
}
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );
Unfortunately this doesnt seem to work
Anyone got a solution for this?
Thanks! | The excerpt length is the number of words, not the characters. Assuming that every word is 8 characters long in average, you might want to use this:
function wpdocs_custom_excerpt_length( $length ) {
if( is_front_page() ){
return 50;
} else {
return 100;
}
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );
Source : WordPress codex | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 2,
"tags": "functions, excerpt"
} |
Woocommerce Force the category choice before creating new product?
How can I force the user to first choose a category product before continuing to the editor when creating a new product?
I found a successful solution but it is working for posts not products. Force category choice before creating new post?
What I did: I changed the following code :
$post_type = 'post';
if ( isset( $_REQUEST['post_type'] ) ) {
$post_type = $_REQUEST['post_type'];
}
// Only do this for posts
if ( 'post' != $post_type ) {
return;
}
To
$post_type = 'product';
if ( isset( $_REQUEST['post_type'] ) ) {
$post_type = $_REQUEST['post_type'];
}
// Only do this for products
if ( 'product' != $post_type ) {
return;
}
It worked, But it Still listing post categories not product categories. | You can resolve this issue by simply specifying the taxonomy you want to display.
$dropdown = wp_dropdown_categories(
array(
'name' => 'category_id[]',
'hide_empty' => false,
'echo' => false,
// Set taxonomy for product categories.
'taxonomy' => 'product_cat',
) );
_Before posting here, you should at least do some research on how this code snippet worked for 'post', you would've found your answer yourself._
**Reference** :
* wp_dropdown_categories() from WordPress codex.
* this SO answer | stackexchange-wordpress | {
"answer_score": -1,
"question_score": -1,
"tags": "categories, woocommerce offtopic, post editor"
} |
How to check WP Customize Control
I trying this directly in my theme:
` $mods = $wp_customize->get_control('header_text'); if (isset($mods)) { echo 'YES'; } else { echo 'No'; } ` But nothing happened. and in debug.log : undefined variable wp_customize... | I'm not sure what exactly you're trying to accomplish, but if you're wanting to manipulate customizer controls until the `customize_register` action has fired. So do something like this:
add_action( 'customize_register', function( $wp_customize ) {
$control = $wp_customize->get_control( 'header_text' );
if ( $control ) {
error_log( 'header_text control exists' );
} else {
error_log( 'header_text control does not exist' );
}
}, 100 ); | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "theme customizer"
} |
"Page Array" displaying in title bar on Front Page
The issue is that the text "Page Array" is displaying in the title bar instead of what was previously there, which was just a "|" separator.
I'm trying to puzzle out why this issue appeared...it came up as I was doing some maintenance work, updating some Wordpress REST API calls to the current syntax...but I can't trace this back to anything I changed.
Has anyone experienced this issue, or do you have suggestions about how to go about debugging it, or override it?
This theme was built using the Sage starter theme.
Any advice is much appreciated. This post has some information but I could track down a function that was causing the issue: < | There are many ways to set page title in wordpress.
1) In admin area go to settings >> General Settings. Set "Site Title" field and "Tagline" field values.
2) You can set your page title using wp_title() function to set the title of your page.
Using this function you can change your page title based on your page.
3) For SEO purpose you can use All in One SEO plugin which allows you to set page title and meta data for each and every page.
4) Also, You can use following jQuery code to remove "page array" string from your page title at the time of page load.
<script>
jQuery(document).ready(function () {
var title = jQuery(this).attr('title');
if(title.contains("– Page Array")){
var title = title.replace("– Page Array", "");
document.title = title;
}
});
</script> | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "php, title, wp title"
} |
How to use defined in class file with namespace
Here is my code.
defined( 'ABSPATH' ) || exit;
namespace JSR;
class myClass{
...
}
This is giving below error
Global code should be enclosed in global namespace declaration
Any idea how to fix it? | From the PHP manual on defining namespaces:
> Namespaces are declared using the namespace keyword. **A file containing a namespace must declare the namespace at the top of the file before any other code - with one exception: the _declare_ keyword.**
To fix the issue, simply make sure that your namespace declaration comes before the other code:
namespace JSR;
defined( 'ABSPATH' ) || exit;
class myClass{
} | stackexchange-wordpress | {
"answer_score": 3,
"question_score": 2,
"tags": "constants, namespace"
} |
How to add/manage Followers (email subscribers) via API?
I have a Wordpress blog and a Magento store. Both sites are using some kind of Newsletter plugin but I only do want to manage subscriptions via Wordpress.
The Wordpress blog is hosted on Wordpress.com and I'm using the "Follow Blog Widget".
Now I want to create an extension in Magento which pushes new subscriptions to Wordpress. According to the Wordpress Developer API we can use the API to add new Followers but the query parameters do not show any email address.
Is it possible to add new Followers (email subscribers) via API? If yes, any example will be much appreciated.
Using the direct url also does not work (getting an invalid email address):
| This API uses an oAuth2 approach. With the endpoint `/sites/$site/follows/new`, it looks like you'd have to prompt the user to authenticate themselves on Wordpress.com, get back a code, which you then have to exchange on an endpoint for access token. This is all explained here. The information stored in the Access Token you receive after the oAuth2 authentication would hold the user's information, and would be used to add them as a follower of your blog when you make the POST request.
Unfortunately, in as far as I can tell, there is no way to add a follower by email through the API directly.
I know it may not be the ideal solution, but it looks like your best bet is to create a follow button here: <
Of course, you could go through the whole oAuth2 approach, but ultimately it'd probably be a lot easier to just generate the button. Hope this helps. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": -2,
"tags": "plugins, api, subscription"
} |
Hook after image is uploaded and image sizes generated
I'd like to compress images once they're uploaded to media library. Is there any hook that fires once the image is uploaded and the image sizes generated? | > Is there any hook that fires once the image is uploaded and the image sizes generated?
`wp_handle_upload` fires after the image is uploaded. After the follow-up question, I discovered that images would not be sized at this point.
add_filter( 'wp_handle_upload' 'wpse_256351_upload', 10, 2 );
function wpse_256351_upload( $upload, $context ) {
//* Do something interesting
return $upload;
}
Added:
Images are resized on line 135 of image.php. There are no hooks in method to resize the images.
At the end of the wp_generate_attachment_metadata() function, `wp_generate_attachment_metadata` fires. This is after the image sizes are generated.
`wp_read_image_metadata` is another option. It fires before `wp_generate_attachment_metadata` but after image sizes are generated. | stackexchange-wordpress | {
"answer_score": 17,
"question_score": 7,
"tags": "hooks, actions, images"
} |
45mb File Exceeds the Maximum Execution Time
I'm trying to upload a file which is 45mb full of images via plugin **Media From FTP** but it always got an error saying:
> Maximum execution time of 300 seconds exceeded
Is it normal that a 45 mb file to exceed the max execution time?
How should I upload it? | No it's not. Unless you have a connection that is being interrupted, or is very slow. Here is what you can do:
**Option 1**
Increase the PHP max execution time. Ask your host provider to increase it, or if you have access to it, update this line in your `php.ini` file:
`max_execution_time = 999`
**Option 2**
Use a more stable connection with a higher transfer rate. Your host maybe also suffering from bandwidth limitation because of a low quality provider, or a peak in traffic.
**Option 3**
Use a file transfer program such as FileZilla to upload your file straight using FTP.
**Option 4**
Divide your ZIP files into separate files and then upload the individually. This will be your last option if you can't do any of the above. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "uploads"
} |
Adding a variable to a meta field in the backend?
I have a plugin which lets me create retailers. These retailers all have a meta field called commission - the value of which I might need to change down the road. Most of them are just set to 15 at the moment, but if I had to change that to, say, 20, I would have to go into every retailer and change that information.
How do I create a variable instead? | Create a function and execute wp_query for retailer posttype and get all data of retailers and then using foreach loop of that retailers use this: update_post_meta($post_id, 'your_field_name', 'YOUR_NEW_VALUE'); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": -1,
"tags": "plugins, custom field, automation"
} |
make playlist from a custom post type
I have music website and it has a custom post type named Songs and want to do something that users be able to make playlist from musics of my website, name it and share it with other users exactly like spotify.com I searched the web but didn't find anything. Please introduce me a plugin or give me an idea thanks. | I've done something similar.
My approach was to run a query on the post type.
I stored all my song data (MP3 URL, track artist, etc.) in the post meta, then with JavaScript, users could store an object to local storage, session and or cookie, depending on how big the object was.
You can always set up an extra post type called _playlist_ and store a sanitized object in the meta. | stackexchange-wordpress | {
"answer_score": 1,
"question_score": -1,
"tags": "custom post types, plugins"
} |
Wordpress Customazation API section in section
Heyo,
I'm once again stuck with my Customizer API. How can I put my sections together in another Section/Folder (however you wana call it)? Like the standard Widget section:
;
If it's in your child theme, you can simply remove it. If it's in your parent theme, you can add this to your child theme functions.php file.
// in your Child Theme's functions.php
// Use the after_setup_theme hook with a priority of 11 to load after the
// parent theme, which will fire on the default priority of 10
add_action( 'after_setup_theme', 'remove_featured_images_from_child_theme', 11 );
function remove_featured_images_from_child_theme() {
// This will remove support for post thumbnails on ALL Post Types
remove_theme_support( 'post-thumbnails' );
// Add this line in to re-enable support for just Posts
add_theme_support( 'post-thumbnails', array( 'post' ) );
}
< | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "images"
} |
Why is the Links Manager visible?
The admin panel of my WordPress (4.7.2) installation on my hosting (godaddy) has "Links" section enabled.
I set it up a few seconds ago with storefront theme. Then removed storefront and activated starter theme _S (underscores).
Even though I **did not** use following code, the links section is visible. Why is that?
add_filter( 'pre_option_link_manager_enabled', '__return_true' );
 expects parameter 1 to be a valid callback, no array or string given in /wp-includes/class-wp-hook.php on line 298.
Here is my code:
add_submenu_page(
"Add / Edit Price Options in Kilometers",
"Add / Edit Price Options in Kilometers",
"Add / Edit Price Options in Kilometers",
"manage_options",
"crsc-add-kilometers",
include( 'admin/template.add-edit-kilometers.php' )
);
When the actual page renders, this page's html renders before 'wpcontent' div. I hope this make sense. | The last parameter of `add_submenu_page` expects a function callback, not a file include - hence the error as that is not a valid callback. (See add_submenu_page in the codex.) You can include the file in the function if you prefer:
add_submenu_page(
"???",
"Add / Edit Price Options in Kilometers",
"Add / Edit Price Options in Kilometers",
"manage_options",
"crsc-add-kilometers",
"add_edit_kilometers"
);
function add_edit_kilometers() {
include( 'admin/template.add-edit-kilometers.php' );
}
Also, the first parameter needs to be the parent slug menu ID you are adding the submenu to for this to work, you would need to replace `???` above. | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "wp admin, options"
} |
Should nonce be sanitized?
The general guideline is that we should sanitize all user input before using them.
Now my questions is whether this applies to nonce or not.
Which one is correct?
`wp_verify_nonce( sanitize_text_field( $_GET['some_nonce'] ), 'some_nonce' );`
or
`wp_verify_nonce( _GET['some_nonce'], 'some_nonce' );` | Sanitizing is required when you are inserting user input into Database or outputting it in HTML etc. Here, you are simply doing a String comparison.
`wp_verify_nonce` function checks `$nonce` value like this:
if ( hash_equals( $expected, $nonce ) ) {
return 1;
}
For this you don't need sanitizing. So the following is fine:
wp_verify_nonce( $_GET['some_nonce'], 'some_nonce' ); | stackexchange-wordpress | {
"answer_score": 6,
"question_score": 5,
"tags": "sanitization, nonce"
} |
Child theme style.css didn't work properly but the Customize Additional CSS did
I just create TwentySeventeen Child Theme using Wordpress Codex instruction and re-align my site branding with some code. It work but after that I try to style a custom navigation menu with style.css and nothing happen.
I think there are problems with my child theme because when I added the CSS direct on Child Theme Additional CSS, its work.
I have follow this tutorial for custom navigation menu.
<
Please help me in this case, I have search various topic and still can't recognize the problem.
Sorry for my bad grammar and please bear with me if I make any mistake as this is my first time ask question on stackexchange. Thank a lot. | Maybe your stylesheet is not loading. In a child theme you should have a file called functions.php which enqueues your styles. If you aren't enqueuing your CSS then if you view your source you will not see that file being called. | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "functions, css"
} |
WP Customizer API loaded into functions.php
Heyo,
I'm once again sort of stuck with my Customizer API. I've worked quiet a lot on the Theme Customization of my Theme and my functions.php is getting a bit out of hand. Is there a way I can put all these "panels/sections/settings/controls" in an extra file and just load that file into the functions.php?
And even thoe is there a way I can load that file only if the Customizer is open?
Thanks in advance! | Yes. You can load the code in the `customize_register` action. One example:
<?php
// File: functions.php
add_action( 'customize_register', function( $wp_customize ) {
require_once dirname( __FILE__ ) . '/inc/customize.php';
wpse256532_customize_register( $wp_customize );
} );
And the `inc/customize.php` file:
<?php
// File: customize.php
function wpse256532_customize_register( $wp_customize ) {
$wp_customize->add_setting( /* ... */ );
$wp_customize->add_control( /* ... */ );
// ...
}
// ... any additional customizer classes and other includes ... | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "functions, theme development, theme customizer, api"
} |
Adding additional taxonomies to wordpress taxonomy page
I have a custom post type 'packages' with multiple taxonomies; i.e. 'destination'
i.e. mysite.com/destination/new-zealand/
The post type 'packages' also has other taxonomies, i.e. 'difficulty'
I wish to filter these area pages; something like: mysite.com/destination/new-zealand/?difficulty=medium
Here is the WP_Query:
$term_id = "12"; //medium
$taxquery = array(
'posts_per_page' => 1,
'post_type' => 'packages',
'tax_query' => array(
array(
'taxonomy' => 'difficulty',
'field' => 'term_id',
'terms' => $term_id,
'operator'=> 'IN'
))
); | // 12 - difficulty
// destination
// get Id current taxonomy
$this_term = get_queried_object();
$taxquery = array(
'posts_per_page' => 1,
'post_type' => 'packages',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'difficulty',
'field' => 'id',
'terms' => array( 12 ),
),
array(
'taxonomy' => 'destination',
'field' => 'id',
'terms' => array( $this_term->term_id) // Id current taxonomy
)
)
); | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 0,
"tags": "wp query, custom taxonomy"
} |
Return only post(s) which have post_excerpt
I'd like to grab a random post but only one which has a post excerpt. Is there any way that I can query this during a call to `get_posts()` or `wp_query()`?
Bonus points if I could do it with REST, I explored down that route and found myself back at `get_posts()`. | Something along these lines should work, not tested for syntax errors though
function random_post() {
$args = array(
'post_type' => 'post',
'orderby' => 'rand',
'posts_per_page' => 1,
);
$post = query_posts( $args );
}
if(!$post->post_excerpt){
random_post();
}
// Then down here you would do whatever with the $post object | stackexchange-wordpress | {
"answer_score": 0,
"question_score": 1,
"tags": "wp query, get posts, excerpt, rest api"
} |
How to Create a Admin User for A WordPress Site via MySQL (PHPMyAdmin)?
My WordPress site got hacked and the WP Admin user account password was changed by the hacker. This essentially locked the user out of his admin dashboard. It is best (for situations like this) to just create a new admin user account to gain access to WP admin dashboard and fix things as needed.
Is it possible to create a new WordPress admin user account via MySQL database (without having access to your WordPress admin dashboard).
**N.B: I am site owner and I have access to cPanel/Control Panel of my server.** | You need to run those below queries-
INSERT INTO `your-wp-database`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`, `display_name`) VALUES ('1000', 'your_username', MD5('Str0ngPa55!'), 'your_username', '[email protected]', '0', 'User Display Name');
INSERT INTO `your-wp-database`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '1000', 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');
INSERT INTO `your-wp-database`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '1000', 'wp_user_level', '10');
But notice here **_your-wp-database_** is the name of your WordPress database, **_1000_** is your newly created user's ID, **[email protected]_** is the user email, the **_your_username_** is your user's username, **_User Display Name_** is your newly created user's display name and lastly **_Str0ngPa55!_** is the password of your newly created user. | stackexchange-wordpress | {
"answer_score": 4,
"question_score": 1,
"tags": "mysql, phpmyadmin, password"
} |
Show (print) featured image all dimensions (height, width)
<a class="classname" href="<?php the_post_thumbnail_url( 'full' ); ?>">Full Image</a>
Im using this code: Output is text "Full Image" linked to the post url of the full featured image. What I want to achieve is to add dimensions to show for that image as f.e:
"Full Image 600x400" or Only "(600x400)"
Thanks! | Add this function to your functions.php file:
function show($size = NULL) {
global $post;
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
if(isset($size)){
$image_data_array = wp_get_attachment_image_src($post_thumbnail_id,$size);
}else{
$image_data_array = wp_get_attachment_image_src($post_thumbnail_id);//Default value: 'thumbnail'
}
echo $image_data_array[1]."x".$image_data_array[2];//here you can add more chars of strings if you want
}
and use it like this:
<a class="classname" href="<?php the_post_thumbnail_url( 'full' ); ?>">Full Image <?php show('full'); ?></a>
this is outputting `WidthxHeight`, you can use any default image size `thumbnail, medium, medium_large, large, full` or any custom size you have added using add_image_size() | stackexchange-wordpress | {
"answer_score": 1,
"question_score": 0,
"tags": "images, post thumbnails"
} |
Forgot your password points to main blog on multisite install
I have set up a Wordpress multisite install, with two blogs - let's call them site1.com and site2.com .
When I access < the 'Forgot your password link' points to < which is quite confusing.
How can I fix the link to point to point to site2.com? | See the answer here: Password Reset for Users on a Multisite Subsite . It shows the code that a plugin uses to set the link to the subsite's lost password, rather than the main site (which is what WP does by default).
You could add that code to your Child Theme's function.php (so you don't mess with the theme code, which will overwrite your changes during theme update). | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 1,
"tags": "multisite"
} |
Custom redirect user after login based on metadata
I have a problem and would like some help:
Scenario:
Table: wp_usermeta
, which function could I use for all users with Special Plan after login being redirected to the website.com/special page, Super plan users being redirected to the website.com/super page and users of the Vip plan being redirected to the website.com/vip page? | This should do the trick. Add this filter to your plugins functions file/class. This will run automatically every time anyone logs in, if they are a user who has the 'Vip' plan, they will be redirected to the `/vip/` page. otherwise they will be redirected to the default.
add_filter( 'login_redirect', function( $redirect_to, $request, $user ) {
if( ! is_wp_error( $user ) && 'Vip' == get_user_meta( $user->ID, 'plan', true ) ) {
return home_url( 'vip' );
} else {
return $redirect_to;
}
}, 10, 3 ); | stackexchange-wordpress | {
"answer_score": 2,
"question_score": 0,
"tags": "redirect, login, user meta"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.