Home › Forums › Weaver Xtreme Theme › How do I use a function result within a shortcode (specifically parallax)
- This topic has 4 replies, 3 voices, and was last updated 10 years, 11 months ago by
Weaver.
-
AuthorPosts
-
September 29, 2015 at 02:31 UTC #18325
Qoheleth
ParticipantI’ve inserted some functions into the Actions & Filters area. rms_get_S2BG_url returns the url of a background image uploaded to the site based on a theme setting in the user’s profile. The function works as it should, but I can’t seem to figure out how to embed the results into the Parallax short code. What I get instead is just the code itself, echoed to the page. What am I doing wrong?Here’s the code in the page that”s supposed to show the parallax as well as a parallax command where I simply inserted the url manually so I can see how it would look if it was working properly.[php] $plax_url=rms_get_S2BG_url(‘worship’); echo $plax_url.”</br>”; echo “[parallax img="" . $plax_url . "" height=200]Worship Services Index[/parallax]“[/php][parallax img='http://www.disciplesnet.org/wp-content/uploads/worship-classic.jpg' height=200]Worship Services Index[/parallax]September 29, 2015 at 02:50 UTC - Views: 1 #24822scrambler
ModeratorI dont know for sure, but if I had to guess this means that the page content is only interpreted once.The way you have it, it would have to be interpreted twice, once to interpret the php that produces the shortcode, then a second time to interpret the resulting shortcode.Unless someone who knows WP and PHP logic better than me comments, I would try with the PHP inside the shortcode. Something like below (do check the quote syntax as I am not savy in PHP)[parallax img=[php] $plax_url=rms_get_S2BG_url(‘worship’); echo ‘”‘ . $plax_url. ‘”‘ ;[/php] height=200]Worship Services Index[/parallax]September 29, 2015 at 10:24 UTC - Views: 4 #24823Qoheleth
ParticipantYes, I was pretty sure it was something about not interpreting in the right order or only once. At any rate, the code you suggested does indeed give a parallax segment, but the background image comes our url(http://www.disciplesnet.org/test-page/%5Bphp) (the url of the page itself eith “[php” appended) and the text overlay is $plax_url=rms_get_S2BG_url(‘worship’); echo ‘”‘ . $plax_url. ‘”‘ ;[/php] height=200]Worship Services Index.
Incidentally, the following code does work to insert the full bacground image into the page:[php] $plax_url=rms_get_S2BG_url(‘worship’); echo ‘<img src=”‘ . $plax_url . ‘”>’;[/php]but putting the <img src= and > bits outside of the php code doesnt.September 29, 2015 at 19:12 UTC - Views: 4 #24824scrambler
Moderator@Qoheleth Doing some search I came acrosshttps://wordpress.org/support/topic/how-do-i-execute-shortcode-in-my-php-code-only
So I tried
[php] $plax_url=rms_get_S2BG_url(‘worship’); echo do_shortcode(“[parallax img=" . $plax_url . " height=200]Worship Services Index[/parallax]“); [/php]And that appears to workThe echo do_shortcode is the key here and you would have been better searching the codex or developer sites for this kind of question 🙂September 30, 2015 at 02:39 UTC - Views: 1 #24825Weaver
KeymasterSorry I didn’t see this sooner, but indeed, if you want to see output of a shortcode from within PHP code, you have to wrap it with do_shortcode().
-
AuthorPosts
- You must be logged in to reply to this topic.

