Retrieve a custom form field modified by a filter

I figured out how to proceed. I created a text file with the desired select options and just replaced the input field from the template with the bellow code. <?php $file_path=”FILE_PATH_HERE”; // path to the file with select options if ( !file_exists( $file_path ) ) { echo ‘<input type=”text” name=”location” placeholder=”‘ . __(“Location …”, “custom-settings”) … Read more

custom COOKIE on custom page

If all you are doing is setting a cookie on a page then why the complexity? Check this out for a simple answer http://www.w3schools.com/php/func_http_setcookie.asp My only thought is that you are then trying to redirect them back to WordPress and if so you may wish to check this Setting custom cookies in WordPress I’d say … Read more

How to run a function when publish posts? [duplicate]

Unless you have a very specific reason, and you know what you are doing, code like this belongs in the functions.php file or a dedicated plugin. WordPress uses two kinds of hooks to allow certain functions to be triggered at specific times. These are called Actions and Filters. https://codex.wordpress.org/Plugin_API Placing code in a file that … Read more

Insert menu into theme location depending on user logged in/out status

Okay, figured it out! I’ve amended my theme function as follows: add_filter( ‘wp_nav_menu_items’, ‘add_loginout_link’, 10, 2 ); function add_loginout_link( $items, $args ) { if (is_user_logged_in() && $args->theme_location == ‘top_navigation’) { $items .= wp_nav_menu( array(‘menu’ => ‘menu-logged-in’, ‘container’ => ”, ‘echo’ => false, ‘items_wrap’ => ‘%3$s’) ); } elseif (!is_user_logged_in() && $args->theme_location == ‘top_navigation’) { $items … Read more

Different body image backgrounds on different pages, posts and categories

You need to add the classes for the corresponding cases. For pages/posts: $css = “body.page-id-**post_id** { background-image: url(‘$bg_image’); }”; For categories: $css = “body.category-**category_id** { background-image: url(‘$bg_image’); }”; You can retrieve post_id with $post->ID. For the category you need to check whether the page is_archive() and to append the corresponding ID or category name.

Regex works in regexr, but not if I filter content [closed]

Per comments, it’s best to use single quoted strings for regexs in PHP (then only backslash and single quote are special), and only backslash as necessary, eg in this case $url_regex = ‘/href=”https://wordpress.stackexchange.com/questions/219419/(http”https):\/\/.+?”https://wordpress.stackexchange.com/”; (leaving out the positive lookahead which isn’t needed here).