Support » Plugin: Widget Logic » Trouble with PHP

  • Resolved AndrewLeonard


    I added this logic from your examples but it did not work

    global $post; return (is_page('home') || ($post->post_parent=="7651"));

    I have changed the ID number but that is all

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Widget logic use just conditions. Don’t add additional PHP
    If you want to create php code, put either to a code snippet of functions.php of the child theme.

    Thanks for replying but can you explain why this is shown as an example on the plugin page:

    … however if you are correct how would I do this
    I want Widget Logic to make the widget appear on all the children of a page
    What code should I put in functions.php and what code to put in Widget Logic?

    Thank you in advance

    I have always put for widget logic only a condition without if statement, commonly a function


    but of course you can use more complex conditions like

    (some_function() || some_other-function())

    If you put the function, the function just should return true or false on the base, where it has been called. I have been used this kind of system for setting parent page and sub-pages inside my own function

    $currentUrl='https://' . $_SERVER['HTTP_HOST']. $_SERVER['REQUEST_URI'];

    Well, I am afraid to say that
    global $post; return (is_page('7651') || ($post->post_parent=="7651"));
    does work
    It puts the widget on page 7651 and all its immediate children

    The reason I could not get it to work was because the pages used the full-width template and did not allow for any widgets

    Mea culpa

    I didn’t know that I could put other PHP as a condition. $post->post_parent would be usefull also for me.

    I tried to replace
    $blogi = (is_page(‘173’) || ($post->post_parent==”173″));

    but that didn’t work.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Trouble with PHP’ is closed to new replies.