Articles of php

Password protecting content in custom template

I’m trying to password protect content in a custom page template, however when i enter the password i assigned in the backend, it doesn’t authenticate, instead just reloads the page upon submission. I know the code below isn’t great, but please try to disregard this – I just need help getting the password authentication to […]

How to use return in my custom function instead of echo

I’m creating a function in functions.php with a custom hook, and from what I’ve read somewhere, it’s good practice to return instead of use echo in a WordPress function? Correct me if I’m wrong. Anyway, so with echo, my function works, but breaks everything else. With return, the function is no longer outputting anything, but […]

How to run PHP code in Text Widget with no plugin in WP 4.4

Before I had the following code in the function.php add_filter(‘widget_text’,’execute_php’,100); function execute_php($html){ if(strpos($html,”<“.”?php”)!==false){ ob_start(); eval(“?”.”>”.$html); $html=ob_get_contents(); ob_end_clean(); } return $html; } Then I have updated WP to the version 4.4.1 and now it’s not working anymore. Is there any other solution?

wp_delete_post deletes all posts instead of just expired ones

I am trying to set up a cron job which deletes posts which have past their expiry date (i.e expiry date < today’s date). I have a meta box on the custom post type which adds an expiry date to the post. I have set up the cron job to trigger the wp_delete_post every hour. […]

Set post title based on first h2 element in the content section

I have a front end editor set up for users to create posts and I would like to make it as simple as possible to create posts with the least amount of fields involved. Is it possible to generate the post title based on the first h2 element that appears in the content field? How […]

Creating bulk posts with Youtube videos

I’m a bit new to WordPress and I’m a bit lost reading all sort of docs about creating bulk posts using PHP. I’ve wrote a small code that using Youtube API v3 to get all the videos from a Youtube channel and I want to create post in wordpress using that loop and data. My […]

How Can I Call Up The Author's Name on a Post

For some reason my by author disappeared and I cant turn it back on. I know where I want to put it on single.php at the end of the post, but I can’t figure out what code I have to put in for it to display.

how to save selection meta data in user profile on frontend

Hi can anyone help me to save the post title selected in this select box? I would like to let people select posts out of a dropdown select box and save the value to their profile. Help is very appreciated! add_action( ‘show_user_profile’, ‘product_selection_field’, 5 ); add_action( ‘edit_user_profile’, ‘product_selection_field’, 5 ); function product_selection_field( $user ) { […]

How do I turn a shortcode into php?

I need to add a shortcode into one of the php files (replacing a search bar code that is hardcoded into the header php file). How do I add a shortcode to the header php file? This is the code that I am looking at: <?php if ( (is_front_page()) && (of_get_option(‘g_search_box_id’) == ‘yes’) ) { […]

Unusable menus and “Illegal widget setting ID: nav_menu_item” error

This is a bug in my WP install that has crept up unknowingly; I can’t say for sure when it began. To describe it: there were menus created in the Appearance -> Menus page early in the site’s history, and they work perfectly, as in: They have menu items They can be assigned to menu […]