New answers tagged

0

I have three different examples to call the ajax, each has a specific error. I am researching on different websites, blogs and forums on how to solve this. I put a alertto check if the serialize() was working and it is!. But, in the end of script, the browser console returns me status success, value zero and isn't being made the operation of the function ...


0

Change the_field() to get_field() the_field() = echo get_field()


1

When you are concatenating string you shouldn't use ;after the method. Also you should close que quotes, call the method, and open again. Try the code below: $listItem .= '<div id="agenda-block-image-responsive" style="' .get_field('speaker-img' ) . '">';


0

I would suggest googling "wordpress ajax tutorials". Here is one that was beneficial to me. https://premium.wpmudev.org/blog/using-ajax-with-wordpress/ The first problem I see is you have not stated what your 'action' variable is. The JavaScript AJAX call specifies what function is targeted in the 'action' attribute. In WP, this is the hook executes your ...


0

You've got the $content available to you in your remove_p function - so inside that function just look for the existence of a special string (i.e. your "shortcode"), to allow the filter to do the str_replace. For example: if ( false !== strpos( $content, "[p-filter]") ) { $paragraphs = array("<p>","</p>","[p-filter]"); $...


0

The page_template filter is deprecated now. (http://adambrown.info/p/wp_hooks/hook/page_template) Try using single_template (or archive_template for archive templates) instead. Based on @t31os's answer: // Filter page template add_filter('single_template', 'catch_plugin_template'); // Page template filter callback function catch_plugin_template($template)...


0

WordPress uses that when it resizes images to set the quality, but it will not go back and resize images it's already processed. If it did, your site would be continuously checking your uploads and grind to a halt You have these choices: Delete your attachments and reupload them Use a tool such as the regen thumbnails plugin to recreate the images ( will ...


-1

Have you enabled debugging in wordpress? Open wp-config.php in the root wordpress folder and change this line: define('WP_DEBUG', false); to define('WP_DEBUG', true); Your PHP errors will then output to the screen.


1

function custom_function_redirect() { if ( isset( $_GET[ 'link' ] ) && $_GET[ 'link' ] != '' ) { wp_redirect( $_GET[ 'link' ], 301 ); }else{ die('test'); } } add_action('template_redirect','custom_function_redirect'); Try this it worked for me. For redirection you should hook the function in template_redirect


0

Loading almost any (if not all) WordPress files directly will give nothing more than a white screen of death if you have your error reporting set properly. This is because it will trigger a fatal PHP error stopping the execution, and the correct public settings for error display is to not show them. However, if you are trying to mask that you are using ...


5

Does it need it? Probably not (other than this edge case, props @bravokeyl). Should you add it? In my opinion, yes: From a coding/architecture POV, you're declaring "this file needs WordPress". Any direct hit to one of your theme's files (curious users, bots, "script kiddies" etc.) has the potential to leak a little bit of info (most likely filesystem) and/...


2

No, functions.php would generate PHP fatals if loaded directly as it uses the WordPress API. If functions.php tried to bootstrap and load WordPress however, then yes, it would be necessary, but if you've done that then something has gone horribly wrong and you need to start from scratch


2

Most of the times there is no need to check for defined( 'ABSPATH' ) in the child theme.


0

This kind of questions is better asked on StackOverflow community. Maybe this JS hack would help: var elem = document.querySelector('.search-form input[name="search_keywords"]'); if ( null !== elem ) { elem.onchange = function() { var e = this , v = e.value; if ( ! v ) return; v = v.toString(); if ( 0 === v....


2

get_template_directory_uri() will always return the URI of the current parent theme. To get the child theme URI instead, you need to use get_stylesheet_directory_uri(). You can find these in the documentation, along with a list of other useful functions for getting various theme directory locations. If you prefer to use a constant, then TEMPLATEPATH is ...


1

The hook to use is wp_enqueue_scripts instead of wp_print_scripts


1

Looking at the id's in your rendered code, the name of your parent style seems to be 'basic-css'. That would mean you need array('basic-css') as the dependency in your wp_enqueue_style. However, in the code the child style seems to be called 'defaultbasic-css', while you enqueue it as 'child-style'. So it looks like there is some relevant code missing.


1

As suggested in the comments, these kind of modifications would be better served with a custom plugin, as they are not theme dependent. Here's an example: <?php /** * Plugin Name: Remove Footer Text * Description: Remove admin footer text and update footer text through filters. * Version: 0.0.1 * Author: Name * Author URI: http://example....


0

First, make sure you have a Page set up with the slug "join". This page must exist if you expect to point visitors there. Second, using this filter will NOT redirect you to the /join/ page when you directly visit wp-login.php. It only replaces the URL WordPress uses when generating links/URLs to the default signup form. It sounds like what you're wanting ...


2

Samuel Elh correctly answered this. if ( $type === 'portfolio' ) { $terms = get_the_term_list( $post->ID, 'royal_portfolio_cats', '', $separator ); $term_array = explode(',',$terms); if ( $limit = array_slice($term_array, 0, $max = 5) ) { echo implode( ", ", $limit ); if ( count( ...


0

Finally I found the solution in codex.... Interpreting the Error Message: If the error message states: Warning: Cannot modify header information - headers already sent by (output started at /path/blog/wp-config.php:34) in /path/blog/wp-login.php on line 42, then the problem is at line #34 of wp-config.php, not line #42 of wp-login.php. In this ...


0

Create a plugin for the mu-plugins directory and have your function run when the wpmu_new_blog action fires. Reference, here: https://codex.wordpress.org/Plugin_API/Action_Reference/wpmu_new_blog The hook you cited for ACF seems to be the way you ought to run you function, if you want that to happen upon ACF save...


1

If you will not pass that how many arguments you need in your callback function then add_filter will provide you only one and first argument. Because default arguments for add_filter are add_filter ( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 ); $accepted_args is 1 if you do not pass it. Thus $args is always ...


2

checked() will echo the result by default. That's the problem. To concat, you need to disable echo functionality by specify third param to false: echo '<input type="checkbox" id="my_meta_box_check1" name="my_meta_box_check1" ' . checked( $check, "on", false ) . '/>';


0

To do what you want you are going to have to add_rewrite_rule for each rule you have. I am storing new rules that users add to an options array. If the user wants to delete the rule, then once selected, I unset it from the array. function remove_rule($user_input){ foreach($rules as $key => $rule){ if($rule === $user_input){ unset(...


0

What you want is probably better to do with css by applying a display:inline; style to the specific widget. something like #id.textwidget { display:inline; } Where "id" is the id attribute of the widget. If you don't have one you should change your sidebar registration code to create one. I don't think it is very likely that you will want such a ...


1

More than likely this is an issue with the register_sidebar() call in functions.php. Look for before_widget and after_widget. The code below is the default usage. 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', Note: This will alter all of the widgets within the sidebar, not just the TextWidget.


0

Searching around and not being able to implement the action through init hook I've found this workaround which for sure isn't the best but does the job nicely. echo "<script type='text/javascript'> window.location=document.location.href; </script>"; at the end of $_POST instructions. If somebody has a better solution, welcome ...


0

The right function to use is: plugin_dir_path(); Example: include_once plugin_dir_path( __FILE__ ).'plugin-functions.php';


-1

If you're feeling lazy you could also do require_once( ABSPATH . PLUGINDIR .'/pluginname/pluginfunctions.php' ); This helps if you like to keep your code lines short but isn't much different from pbd's answer.


2

You also need to include the RTL.css file which is in the theme too: add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); function my_theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'rtl-style', get_template_directory_uri() . '/rtl.css' ); } To use the rtl.css from ...


0

It's because your function archive_action is executed when the loop was already made. Try hooking your function into the init action, so it would be executed before the loop. Another prettier approach would be using ajax. So you send the request through Ajax to archive and just use javascript to remove the post from the DOM.


2

You really shouldn't be doing this. Functions belong in the functions file. Period. (Or perhaps in a separate functions file which you include in the main one) However, if you insist, you can drop functions in any template file you want, because PHP doesn't care. Actually you will need to include it in every template file where you want to call ...


0

The enqueue_parent_theme_style() and my_jquery_enqueue() functions do not have closing brackets. Does the above code run? Otherwise the code looks okay. Are running WordPress with WP_DEBUG set to true? https://codex.wordpress.org/Debugging_in_WordPress I use the following in my wp-config.php file: if ($_SERVER['REMOTE_ADDR'] == '123.456.789.123') { ...


0

Agree with the Hugh Man that it is better to check the option before echoing the link, but it is possible to set the static page as a front page and leave the posts page empty. In this case, the link will just point to the home URL. A better approach is to provide a fallback to the posts archive page. Something like this: function slug_all_posts_link() { ...


0

The get_avatar filter accepts 6 parameters, not 5. The $id_or_email can also be an instance of WP_Post, WP_User or a md5 hash string. So it's better to extract $user_id like this: if ( is_numeric( $id_or_email ) ) { $user_id = $id_or_email; } elseif ( is_string($id_or_email) ) { if ( is_email($id_or_email) ) { $user = get_user_by('...


0

In any foreach loop, the last value of the array being looped over remains after the end of the foreach loop. That is why one should actually always unset that value after the foreach loop is done. wp_list_pluck() is also just a basic foreach loop if $index_key is not passed. Also, as with any foreach loop, the last value of the array remains after the end ...


3

Gallery Image Caption - As Title Of The Post It's attached To Here's one way to do it with a custom parent_titles attribute in the native gallery shortcode. This can be achieved by setting suppress_filters to false for the gallery query and modify the posts excerpts through the the_posts filter. We can then check for the custom attribute inputs through ...


-1

Depending on where in the loop you call excerpt() wpautop might be creating the <p>...</p> wrapper. In that case, you could wrap $excerpt with <p>...</p> before returning it. Edit: Try this approach <?php echo excerpt(25)."\n";?> (or possibly "\n\n") to change the behavior. in function awesome_excerpt() you have $text = ...


0

You have no need callback function. Only reverse_top_level: true is find for what you want to do. Just remove 'callback' => 'custom_comments_callback', from your array. <?php wp_list_comments(array( 'reverse_top_level' => true, 'avatar_size' => 50, 'reply_text' => 'Reply to this comment' )); ?>


0

First the way to do this is with a form using the post method, it is slightly easier to understand: <!-- form with AJAX action and iframe target --> <form method="post" action="<?php echo admin_url('admin-ajax.php'); ?>" target="emailsendframe"> <!-- AJAX action field to trigger function--> <input type="hidden" name="action" value=...


1

I wonder if you mean to register a file-less template with the theme_page_templates filter like this: /** * Add a file-less page template to the page template dropdown */ add_filter( 'theme_page_templates', function( $page_templates, $wp_theme, $post ) { // Edit this to your needs $fileless_theme_slug = 'my_fileless_page_template'; $...


1

I still run into the desire to do this kind of thing and have settled on the following solution which I proposed in the OP and like for a couple reasons: It's very transparent and feels consistent with keeping the logic in the theme. It makes it very easy to customize a template later if needed. Custom Template Here's the entire template file if I don't ...


0

Found a solution. Adding this code below to the functions.php file of your theme will do the trick. if ( ! isset( $content_width ) ) $content_width = YOUR WIDTH HERE;


-2

This is an old plugin, but I think you will get idea from this plugin Similar thing is possible with this plugin, you will find more details in plugin description. Alternatively you can use "pre_get_posts" action in your theme's functions.php file to call only on category archive page using below code. Below code will add filter on the category.php page ...


2

If I understand you correctly you want to change the subject line of the email. The hook of your code only changes the content of the e-mail. There's a different hook for the subject: add_filter('comment_notification_subject', 'wpse_228315_comment_notification_subject'); function wpse_228315_comment_notification_subject($subject, $comment_id){ return "...


1

The cookie is stored on the user's computer. The page is generated on the server. Somehow, you must make sure the cookie is transported back to the server when the user clicks on a link to fetch a second page. The instrument for this is javascript. You must send a script with the page that reads the cookie and adds the cookie content as a query_var to any ...


2

Try get_image_tag filter: add_filter('get_image_tag', function($html, $id, $alt, $title, $align, $size) { return $html . '<div>some piece of code here</div>'; }, 10, 6); References: get_image_tag() get_image_send_to_editor() wp_ajax_send_attachment_to_editor()


1

Choose the right place in (rendering-)time First off, you are hooking at init, while you want to add your callback on wp_enqueue_script. Example: add_action( 'wp_enqueue_script', function() { wp_deregister_script( 'jquery' ); // Rest of logic } ); Staying up to date with core Also, you might want to use the correct version that core uses. I ...


2

If you mean to attach it to any and all $_POST inputs in WordPress that's probably falls under Bad Ideas. WordPress has some kinks in how it works with that data (for example it emulates "magic quotes" mode, long deprecated in PHP itself) and some cases of POST in WP are extremely heavy (saving menus in admin for example). You can (and should) sanitize data ...



Top 50 recent answers are included