Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display SVG in front end (Question) #7

Open
Fortyfive opened this issue Oct 6, 2017 · 7 comments
Open

Display SVG in front end (Question) #7

Fortyfive opened this issue Oct 6, 2017 · 7 comments
Assignees
Labels

Comments

@Fortyfive
Copy link

Hi, I have managed to populate the select field but cannot seem to display the output on the front end. Are you able to provide an example? Thanks in advance...

@MaximeCulea MaximeCulea self-assigned this Oct 6, 2017
@MaximeCulea
Copy link
Contributor

Hi @Fortyfive,

We are using a function in front to display all SVGs and of course also the retrieved icon from the svg selector : bea_the_icon( str_replace( 'icon-', '', $icon ) );

As the classname representing the SVG icon is fully retrieved, we must take off the icon- part. The following helper already handle it :

<?php
/**
 * Get the theme's icon display depending on given type
 *
 * @var string $type
 *
 * @author Maxime CULEA
 *
 * @param $type
 *
 * @return string
 */
function bea_get_the_icon( $type ) {
	return sprintf( '<svg class="icon icon-%1$s" aria-hidden="true" role="img"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-%1$s"></use></svg>', esc_attr( $type ) );
}

/**
 * Display the theme's icon display depending on given type
 *
 * @var string $type
 *
 * @author Maxime CULEA
 *
 * @param $type
 */
function bea_the_icon( $type ) {
	echo bea_get_the_icon( $type );
}

Does it sounds good for you ?

@Fortyfive
Copy link
Author

Fortyfive commented Oct 6, 2017 via email

@Fortyfive
Copy link
Author

Sorry Maxine, I still seem to be struggling. I cannot seem to get the syntax correct that appears in the page template to display the chosen icon. How do I add the ACF field name?

@MaximeCulea
Copy link
Contributor

Please have look to official documentation : https://www.advancedcustomfields.com/resources/get_field/

@Fortyfive
Copy link
Author

Fortyfive commented Oct 9, 2017 via email

@srikat
Copy link

srikat commented May 6, 2019

Has anyone figured out how to display the selected icon for a custom field named say, title_icon as a SVG file on the front end?

I managed to show it as an <img>.

@hansmorb
Copy link

Hey, I am unfortunately also having issues. The field populates but the resulting HTML just looks like this:

The actual icon is not showing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants