Archived topic
How to Execute PHP when wp-config can't be amended?
7 replies · Started by Chantal on February 26, 2019
Hi there, hoping you can help.
My hosting company has added the following to my site's wp-config:
The constant definition has now been added to the website's wp-config.php file:
rskeens@web125:/data/s3500/dom7210/httpdocs$ grep GENERATE_HOOKS_DISALLOW_PHP wp-config.php
define( 'GENERATE_HOOKS_DISALLOW_PHP', true );
But the DISALLOW_FILE_EDIT is still defined. When I said it doesn't seem to have had any effect, they responded "the DISALLOW_FILE_EDIT constant definition is always set as true for customers on our shared platform due to the inherent security risks associated with enabling it."
Is there any point in having that in the config file if the Execute PHP checkbox is still not accessible?
I really need to execute the following code in the before_header hook (as WP-Toolset conditionals don't work well here because the shortcode text displays in the screen reader on the site):
<php if ( !wp_is_mobile() ) : ?;
[wpv-view name="sitewide-advert"]
<php endif; ?>
I know nothing about PHP. I wonder, can this be turned into a function and added to Code Snippets?
Hi there,
you can try this in Code Snippets:
add_action( 'generate_before_header', 'db_execute_shortcode' );
function db_execute_shortcode() {
if ( !wp_is_mobile() ) {
echo do_shortcode( '[wpv-view name="sitewide-advert"]' );
}
}
Hi Dave,
Thanks for your response. That's not working unfortunately. If I delete the shortcode in Elements, the sitewide advert (the top banner displaying at the very top of the site) disappears completely which means the snippet hasn't worked.
I am trying to achieve the following: the top banner to disappear only if the site is viewed on a mobile device but to show on a desktop.
I achieved this using conditional hooks but the shortcode text was displaying. The source code showed it was something to do with the Screen Reader. I contacted Toolset about this and they said Execute PHP was the way to go.
Can you test this in Code Snippets:
add_action( 'generate_before_header', 'db_snip_test' );
function db_snip_test() {
if ( !wp_is_mobile() ) {
echo "I appear only on desktop";
}
}
Let me know if the echoed text appears
Hi David, yes it does on the desktop. I'll leave the code snippet activated if you want to see the text on the site.
Can you retry the code here i made a small edit.
Yippee! Thank you David, that has worked. :)
Should I ask my hosting company to remove the GP constant definition from wp-config? Or does it actually make a difference?
Awesome! I don't think its going to make any difference if that is still there.